0

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?

Vignesh Babu
  • 670
  • 13
  • 30

2 Answers2

0

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.

Jody Hagins
  • 27,943
  • 6
  • 58
  • 87
0

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.

Mundi
  • 79,884
  • 17
  • 117
  • 140