How can you have relationships between realms (partitions)?

Is it possible to have direct realm object relationships from one partition to another?

i.e. if I was to expand on the example on the to-one relationship between a Person and a Dog found below:
https://docs.mongodb.com/realm/dotnet/relationships/

Lets assume the Person and Dog belong to some private user partition. Now I would want to add on a Breed to the Dog, lets assume the Breed is some domain lookup data that lives on the PUBLIC partition.

Is it possible to have a relationship between the 2? Something of the sorts in the Dog schema:

    {
      "breed": {
        "ref": "#/relationship/mongodb-atlas/my-db/Breed",
        "foreign_key": "_id",
        "is_list": false
      }
    }

Right now my issue is that if I try to fetch the Breed documents from the user (private) partition/realm nothing is found (makes sense), but if I try to reference the Breed in my dog then add the Person+Dog to my user realm I get the below exception (which also makes sense):
Realms.Exceptions.RealmObjectManagedByAnotherRealmException: ‘Cannot start to manage an object with a realm when it’s already managed by another realm’

So is it possible to have an explicit relationships between partitions/realms by some way I haven’t figured out yet, or is the only way to have a reference id to the Breed and reconciliate the data in app with business logic?

Relationships that span multiple Realms are not supported. What you can do is store the primary key of the object you want to reference and look it up when needed, but that’ll obviously not give you the same referential guarantees as direct relationships would.

1 Like

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