I have a Core data model like the User Entity having relationship with multiple entities. I need to delete all the entities that is related to User entity when i try to remove the user in core data.
How to achieve this?
I have a Core data model like the User Entity having relationship with multiple entities. I need to delete all the entities that is related to User entity when i try to remove the user in core data.
How to achieve this?
You need to set the delete rule on your relationships. NSCascadeDeleteRule
will cascade deletes through the relationships.
You can find the full details on each delete rule in the Documentation. Click on Organizer/Documentation and type in NSDeleteRule
for more details.
The easies way is to go to all the relationships in the Core Data model editor, select each and choose the Delete Rule
(which is preset to Nullify
) to be Cascade
.
Now all depending entities will be deleted as well.
Here is the relevant section in the Core Data Programming Guide.