I have this schema:
class A: Object {
var idA = ""
var b: B?
override class func primaryKey() -> String {
return "idA"
}
}
class B: Object {
var idB = ""
var name = ""
override class func primaryKey() -> String {
return "idB"
}
}
So if i want to save an A object:
func updateA(a: A, b: B) {
do {
try realm.write {
a.b = b //Here i get the excepcion
realm.add(a, update: true)
}
} catch { error
}
}
When i call update i can't assign b to a.b, i get: *** Terminating app due to uncaught exception 'RLMException', reason: 'Can't create object with existing primary key value "bKey".' If the b object already exists in the database with that primary key i get that, but if its a new object it works. Im pretty sure long time ago this worked as expected Notice i want to save A updating the B object if one of its properties has changed, like name. And i dont wanto to create another B object, just use the b object that already passed.