Problems with a bundled realm to be used alongside a synced one

Hello everyone,

I have the following situation: I have a Swift project in which I want to integrate a bundled realm with static data from a package locally and a synced realm next to it. Both are independent of each other.

When I use only the bundled realm in a non-synced test project, everything works fine.

But as soon as I use the bundled realm in the project, in which the synced one is, there are problems with the schema of the attached bundled realm models. It seems that this one is checked like the synced one (rasing a schema error: The primary key property on a synchronized Realm must be named '_id' but found 'id') for the non-synced realm - and if you enable development mode on the server - it also wants to upload the model-schema of the non-synced realm…

How can I prevent that the bundled realm is treated like the synced one in the realm client app? How do you manage that these two realms and their data model (schema) remain independent of each other for the realm app and the synced model-schema?

Huh - that’s an interesting issue. I would guess it a result of how Realm is being accessed; sync vs bundled. Also, is this flex or partition sync.

If it’s flex, you must also define what models are sync’ing. Can you include sample code how you’re accessing the local vs the sync realm, and also include the code for the flex sync subscriptions? Perhaps including the non-sync vs sync models may give us some insight.

Hey @Dan_Ivan did you explicitly specify which classes are used in each Realm?

As soon as you’re opening two Realms, all your declarations are assumed to be in both, unless you manually specify this in the config. This is compilation level - it doesn’t know which classes you will use per-Realm unless you say so. There’s no runtime analysis to determine which schemas need including.

That would explain your error. eg:

            var settingsConf = new RealmConfiguration("Settings");
            settingsConf.ObjectClasses = new Type[] {
                typeof(Settings),
                typeof(UserDetails),
                typeof(AppointmentCategoryTypes)
            };
            settingsConf.SchemaVersion = 5;

It would be a nice extension to be able to do this by exclusion - assuming a small subset of classes used in one Realm (maybe bundled) alongside a main Sync realm. Otherwise you have to repeat the explicit setup above for each and every Realm.

@Andy_Dent : Thanks very much! That’s exactly what I was looking for!

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