Re: (Inverse) relationship lost after being set properly
Re: (Inverse) relationship lost after being set properly
- Subject: Re: (Inverse) relationship lost after being set properly
- From: mmalcolm crawford <email@hidden>
- Date: Sat, 25 Jun 2005 00:53:49 -0700
On Jun 24, 2005, at 7:17 PM, Doug Knowles wrote:
Found it. In moving managed objects from one "owner" to another, I
was simply adding the item to the new owner's mutable set
(representing the to-many relationship), without removing it from the
old owner's set. As a result, when I deleted the former owner, Core
Data thought the objects still belonged to it, and nullified the
inverse (to-one) relationship, as specified by my model.
The correct behavior (at least what's working for me now) is to remove
the object from the old owner's set before adding it to the new owner;
something like:
oldOwnersSet = [oldOwner
mutableSetValueForKey:@"myToManyRelationship"];
newOwnersSet = [newOwner
mutableSetValueForKey:@"myToManyRelationship"];
[oldOwnersSet removeObject:objBeingMoved]; // I was omitting this
<<<<<<<<<<<
[newOwnersSet addObject:objBeingMoved];
In general there should be no need to do this -- see "Managing
Relationships" at <http://developer.apple.com/documentation/Cocoa/
Conceptual/CoreData/Articles/cdLifecycleManagement.html#//apple_ref/
doc/uid/TP40001652-207874-TPXREF149>.
What other steps are you taking? What objects are you deleting
when? How is your model defined?
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden