I’m using Sync. I have some data in a collection in a PUBLIC realm, accessible by all users, and a collection of private objects in each user’s personal Realm. I want to setup a many-to-many relationship between these two collections.
Since the collections are not in the same Realm, I have to use foreign keys (strings, the type of my primary keys). I can get back the object by querying the primary keys.
For a list (to-many relationship), here’s what it would look like (example in Swift):
class PublicData: Object {
@objc dynamic var _id: String = ""
override class func primaryKey() -> String? { return "_id" }
// ...
}
class PrivateObject: Object {
var publicDatas: List<String>
// ...
var realData: [PublicData] {
return Array(publicDatas.map { id in
publicRealm.object(ofType: PublicData.self, forPrimaryKey: id)!
})
}
}
My question: is that efficient, querying primary keys in a loop? Is there a better way to do this, am I missing something?