Reputation: 510
Can't create nested object with primaryKey
: I have Media
object with nested Location
object and Comment
object. In all these objects I've already implemented primaryKey
and while I'm trying to create Media
object, I get crash:
realm.add(media, update: true)
Can't create object with existing primary key value ...
By the way, the problem is with Comment
object, but Location
is ok, however, they are implemented similarly.
Upvotes: 1
Views: 454
Reputation: 510
I've found the reason and it's in the wrong functions order. The right order is add Media to Realm and only then assign it to User:
realm.add(media, update: true)
currentUser.media.append(media)
Upvotes: 2