I am using realm-js
to store data for a user on their device with React Native and there is a point in the workflow where I would like to copy all of the data in the local realm into a synced realm (to persist on ROS). I am running into an issue where in our schemas we have created pseudo relationships by adding a property referencing one object into another object and vice-versa and in doing so we have created circular data structures.
This has actually worked fine in the app but now we are attempting to copy the data from the local realm into the synced realm and it crashes, seemingly, because of the circular references.
For example the schemas look something like this.
class Person extends Realm.Object {}
Person.schema = {
name: 'Person',
properties: {
firstName: {
type: 'string',
optional: true,
},
staffAccount: {
type: 'StaffAccount'
},
},
};
class StaffAccount extends Realm.Object {}
StaffAccount.schema = {
name: 'StaffAccount',
properties: {
id: {
type: 'string',
},
people: {
type: 'list',
objectType: 'Person',
},
},
};
In this example when creating a Person you would define a staffAccount property and that staff account property would have a people property which has a list of the people with that staff account and in that list there would be the person initial person in the Person schema.
Is there any way of getting around this problem when copying data from one realm to another?