delete in entity with parent/children relationships calls removeChildrenObject: twice?
delete in entity with parent/children relationships calls removeChildrenObject: twice?
- Subject: delete in entity with parent/children relationships calls removeChildrenObject: twice?
- From: Jesse Grosjean <email@hidden>
- Date: Wed, 29 Jun 2005 12:35:10 -0400
I have overridden - (void)removeChildrenObject: in the Note class
that comes with the OutlineEdit sample application. The problems is
that in some cases when a child gets deleted this method is called
twice on the parent with that same child, is that the expected
behavior? Here's my code:
id a = [NSEntityDescription
insertNewObjectForEntityForName:@"Note" inManagedObjectContext:
[document managedObjectContext]];
id b = [NSEntityDescription
insertNewObjectForEntityForName:@"Note" inManagedObjectContext:
[document managedObjectContext]];
id c = [NSEntityDescription
insertNewObjectForEntityForName:@"Note" inManagedObjectContext:
[document managedObjectContext]];
[a addChildrenObject:b];
[b addChildrenObject:c];
Now there are two cases. If I delete the top object (that has no
parent) in the tree everything works as expected,
removeChildrenObject: is called once for node a (with parameter b)
and once for node b (with parameter b). Case 1.
[[document managedObjectContext] deleteObject:a];
[[document managedObjectContext] processPendingChanges];
This second case creates the problem. If instead I delete node b,
then removeChildrenObject: will be called twice on node a (with
parameter b).
[[document managedObjectContext] deleteObject:a];
[[document managedObjectContext] processPendingChanges];
I can detect this condition and work around it by checking to see if
the object passed into removeChildrenObject: is already deleted and
doesn't exist in the children set, but that seems like a hack. Is
this the expected behavior or am I doing something wrong?
Thanks,
Jesse
_______________________________________________
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