I wonder if I've been doing too much myself, and could be relying on CoreData more. Suppose I have two managed objects, Dog and Tail, which have a one-to-one relationship. Dog has a relationship, tail, that is optional. Its inverse is owningDog. The delete rule from Dog to Tail is cascade. Tail's owningDog relationship is also optional. Its delete rule is nullify.
Both tail and owningDog are generated as retain properties by CoreData.
What do I need to do, minimally to accomplish the following?
- Move Dog A's Tail X to Dog B
- Delete Dog A (without deleting Dog B's new Tail X).
I've been doing something like this, written in full for clarity
-(void)graftThenKill
{
Tail* tempTail = A.tail;
A.tail = nil; // releases X, sets relationship to nil so we can delete without cascading
B.tail = tempTail; // retains X, sets Tail's owningDog to B
[moc deleteObject:A]; // now we have his tail, don't need A
}
Could I replace this with
-(void)graft
{
A.tail.owningDog = B; // Makes A's tail nil, safe to delete A without deleting X?
[moc deleteObject:A];
}