Joseph An
Joseph An

Reputation: 822

How does Realm handle associations?

Are entries in a Realm database unique and referenced?

For example I have Person and Car in my schema and a Person object can have many Cars in a list.

  1. I create a new Person named "Donald"
  2. I create a new Car called "Tesla" and I push that new Car into Donald's list of cars.
  3. If I update Donald's car and change the name to "Tesla Roadster" will I see the changes reflected when I call realm.objects('Car')[0].name?

Upvotes: 3

Views: 430

Answers (1)

Tayschrenn
Tayschrenn

Reputation: 1212

Relationships between Realm objects are direct references between them. Changing an object in Person's cars collection will see the changes reflected in realm.objects('Car')[0] because it's the same object underneath.

Check out Realm Objects & Relationships, which goes into more detail.

Upvotes: 2

Related Questions