Realm's flexible sync configuration issue for embedded Realm model references through other Flutter SDK models

We’re trying to run a query on Realm’s flexible sync configuration for a Realm model that has embedded references to other models on Flutter SDK.
There are two challenges we are facing:

  1. Immediate Result Set returned from the query (given no data is present on local) is
    empty and only works after the app is relaunched when realm sync adds the data to
  2. References to other Realm Objects that are not queried but are embedded in the
    queried object are null by default and there is no way to retrieve them (as not even the
    ObjectIds are returned)
RealmResults<Profile> profileQuery=_realm.query<Profile>("phoneNumber == \$0", [number]);
    _realm.subscriptions.update((mutableSubscriptions) {
    profileQuery = _realm.query<Profile>("phoneNumber == \$0", [number]);

Hey, so for the first problem, you seem to be missing a call to:

await _realm.subscriptions.waitForSynchronization();

This will resolve when the requested data has been downloaded locally. If you don’t include it, the data will still download in the background, you just won’t be notified when the download is complete.

For the second question, there are two problems. First one is that the objects Profile links to are not embedded - note how embedded relationships are declared in json schema. Instead, they’re linking to objects in other collections, which will not be downloaded at this point. We are currently working on a project that will allow you to specify which links you want to include (e.g. mutableSubscriptions.add<Profile>(profileQuery).include("address")) but that’s not ready yet and we don’t have a definitive timeline for when it’ll ship.

Now, the obvious fix would be to switch those relationships to be embedded ones, in which case you’ll receive all the objects along with the original query - the problem is that the flutter SDK doesn’t support embedded objects yet. We have a PR that adds support and we hope to ship it in the near future, but again, don’t have a definitive timeline for when that’ll happen.


Thanks a lot Nikola. That really helps.
Awaiting for embedded objects support for flutter SDK.

Hey, just following up in case you’ve missed the latest release announcement - embedded objects are now supported, so you can give it another shot.

1 Like

Thank you so much for this update, helped in time. Really appreciate it.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.