Core Data: updateChangeCount and setPropagatesDeletesAtEndOfEvent
Core Data: updateChangeCount and setPropagatesDeletesAtEndOfEvent
- Subject: Core Data: updateChangeCount and setPropagatesDeletesAtEndOfEvent
- From: Robert McNally <email@hidden>
- Date: Fri, 8 Jul 2005 05:38:16 -0700
I have put a tiny Xcode 2.1 project up on my web site that illustrates a problem I am dealing with in Core Data:
http://www.arciem.com/TestApp.zip
The project contains two entities: Concept and Relation. Each Relation points to exactly two Concepts-- it's "source" and "target". Each Concept can be pointed to by many Relations as either source or target. When deleting a Concept, all Relations pointing to it should also be deleted, and this is handled by a cascade delete rule.
As far as I can tell, everything is working fine at the NSManagedObject/NSManagedObjectContext level-- A Concept can be deleted and the Relations pointing to it are deleted. The action can also be undone. HOWEVER, when the action is undone the window remains in the "edited" state. Further undos are not possible.
To do and notice:
1. Build and run the application.
2. Open the provided document "OpenMe.testapp".
3. Select either of the two items in the table and click the Remove button.
4. Notice that -[MyDocument updateChangeCount:(NSDocumentChangeType)changeType] is called TWICE, both times with a changeType of 0 (NSChangeDone).
5. Execute the Undo command.
6. Notice that -[MyDocument updateChangeCount:(NSDocumentChangeType)changeType] is called ONCE, with a changeType of 1 (NSChangeUndone).
7. Notice that the window's "isDocumentEdited" state is still YES even though we just undid the Remove action.
updateChangeCount should be called symmetrically on undo and redo, but it is not!
8. Uncomment the line in MyDocument.m with the statement "[[self managedObjectContext] setPropagatesDeletesAtEndOfEvent:NO];"
9. Go through steps 1-6 above again, but notice that updateChangeCount: is now called symmetrically, and that the window's "isDocumentEdited" state is changed correctly.
QUESTION 1: Why isn't updateChangeCount called symmetrically in all cases?
QUESTION 2: Why does calling setPropagatesDeletesAtEndOfEvent:NO work around the problem?
QUESTION 3: What is the proper solution to this issue?
QUESTION 4: What is the proper usage of setPropagatesDeletesAtEndOfEvent? Are there any examples that use it?
--
______________________________________________________________________
Robert McNally, Arciem Engineering <http://www.arciem.com>
626/963-7760
_______________________________________________
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