re: Cascade Delete won't delete Department in Apple Sample Code
re: Cascade Delete won't delete Department in Apple Sample Code
- Subject: re: Cascade Delete won't delete Department in Apple Sample Code
- From: Ben Trumbull <email@hidden>
- Date: Tue, 23 Jun 2009 19:11:06 -0700
Core Data documentation [1] describes the Cascade Delete Rule as
follows:
"Delete the objects at the destination of the relationship. For
example, if you delete a department, fire all the employees in that
department at the same time."
In order to understand another problem, I tried this on this the
inverse relationship in Apple's DepartmentAndEmployees Sample Code
project. That is, in the data model, I selected the Employee -->
Department to-one relationship by selecting the 'department'
relationship in the 'Employee' entity, changed its Delete Rule to
Cascade, added some code to log and -processPendingChanges to the
MyDocument class [2], built, and run.
Running, in a new document, I added an Employee, then deleted it. I
expected that the Department would be deleted also, but it was not.
Now I understand that deleting the Department might wreak havoc in
this particular project, or generate a 'deny' error, but according to
the console log [3] it didn't even try. Can anyone suggest why not?
Your array controller "helpfully" nulled out the relationship first,
so the relationship no longer exists at all by the time you cascade
the deletion.
You'll see it cascade as you expect if you don't bind it into the UI
in this manner. As a workaround, you could create a custom remove
action that deletes the object and calls processPendingChanges directly.
- Ben
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden