class Feed : RealmObject {
var episodes: RealmList<Episode> = realmListOf()
}
class Episode : RealmObject {
var feed: Feed? = null
}
And there is a Feed object feed, and a bunch of Episode objects episode1, episode2, … which are added to list episodes. These are unmanaged objects copied from realm and later modified.
So from what I understand from the documentation, it will also update the relationship feed, but then is it also going to update the relationships of feed, i.e. epiosdes? Does it go through the update process like: episode1 -> feed -> (episode1 -> feed -> ...), (episode2 -> feed -> ...), (episode3 -> feed -> ...) ...
I presume it doesn’t go through the infinite loop, but to what extent does the update process go? Does the updating of episode1 result in the updating of all episodes through the relations?
The question is a little unclear but let me attempt to address two things:
Not exactly. Upserting doesn’t change the relationship between objects. Keep in mind that relationships use references to other objects so updating a property of an object that has a relationship will not affect the relationship - because it’s a reference to an object, not the object itself.
No. Upserting an object has no impact on other objects - only the one being upserted that has a matching primary key. Keeping in mind that per the documentation
UpdatePolicy.ALL: Update all properties on any existing objects identified with the same primary key.
You should not have objects with the same primary key but be aware of that note regarding policy.
realm.write {
val kermit = query<Frog>("name == $0", "Kermit").find().first()
// Update a property on the related object
kermit.favoritePond?.name = "Big Pond"
}
That’s in a write block. What if I have an object kermit (unmanaged) and I change its relations outside of the write block like:
kermit.favoritePond?.name = "Big Pond"
Then I do an upsert on kermit with:
realm.write {
copyToRealm(kermit)
}
Doesn’t it update the object favoritePond in the DB?
So likewise in my case, when the unmanaged objects of episode1, feed, episode2, etc are all changed, then when I upsert episode1, aren’t the changes in feed, episode2, episode3, etc also updated in the DB?