I'm trying out Realm and ObjectMapper.
I have these two models:
class User : Object, Mappable {
override class func primaryKey() -> String {
retu "id"
}
dynamic var id : String
[...]
func mapping(_ map: Map) {
id <- map["id"]
}
}
class Media, Object, Mappable {
override class func primaryKey() -> String {
retu "id"
}
dynamic var id : String
dynamic var owner : VPUser?
[...]
func mapping(_ map: Map) {
id <- map["id"]
owner <- map["owner"]
}
}
Login is fine: the JSON gets mapped correctly and the realm insertion goes fine as well.
The issue arises when I fetch the media remotely. Each media object contains an user object (owner).
This is how the media JSON looks like:
{
"id": "574cd4e6e4b0b7e43219664a",
"owner": {
"id": "574cd462e4b0b7e432196644",
}
}
Now, the User object with that id may exists already, therefore I get this exception:
Can't set primary key property 'id' to existing value...'
Note: I'm using Realm.create(_, update: true) to save the media.
Any clue on how to solve it? Cheers.
