How do I handle the deletion of the following objects? What should my delete rules look like?
Here’s what my object graph looks like:
Boss
- Boss-Department has a many-to-many-relationship
- If a Boss is deleted,
the Departments belonging to that Boss should NOT be deleted (but the
Departments’ relationship to this Boss should be deleted)
Department
- Department-Employee has a many-to-many relationship
- Department-Boss has a many-to-many relationship
- If a Department
is deleted, the Employees belonging to that Department should be
deleted IF they don’t have a relationship to any other Department
Employee
- Employee-Department has a many-to-many relationship
- Employees will never be deleted directly (only through the deletion of a department). Oh happy life!
In this situation the Delete rules for your objects should be handled like this
Boss-Department -> Nullify
Department-Employee -> Deny
Department-Boss -> Nullify
Here is what Apple explains the Delete Rules as
For more information check out the CoreData Programming Guide