Riki Rikmen
Riki Rikmen

Reputation: 35

Realm Model Relationship

Is it possible to have model like this ?

public class Person extends RealmObject {
private String id;
private String name;
private RealmList<Dog> dogs;
private RealmList<Toy> toys;
}

public class Dog extends RealmObject {
private String id;
private String name;
private String color;
private RealmList<Toy> toys;
}

public class Toy extends RealmObject {
private String id;
private String name;
}

the relationship that i want between these models are Person have can have multiple dogs, and a dogs can have multiple toys. But i want a Person can track deh Toy too and a person can have multiple toys. please help

Upvotes: 0

Views: 217

Answers (1)

Christian Melchior
Christian Melchior

Reputation: 20126

Those models are valid in Realm, but we do not enforce any transitive constraints. If you think of Realm as just an object graph, you should get the idea on what rules you need to enforce yourself.

So if if a Person is only allowed to have Toys that are held by Dogs owned by the Person, you will have to enforce that yourself.

Upvotes: 1

Related Questions