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.
答案 0 :(得分:2)
我找到了原因并且它的功能顺序错误。正确的顺序是将Media添加到Realm,然后将其分配给User:
realm.add(media, update: true)
currentUser.media.append(media)