Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting Relationship Objects with Cascade in Core Data

I'm looking to perform some simple deletion with Core data but just need a bit of advice on this one please.

I have a model with Transaction, Name, Event and Date Entities. The Transaction has a link to each of the other Entities.

In the app, when a user adds in information to text fields, that gets saved to a 4 tab table view controller.

The first tab is using NSFetchedResultController with a fetchRequest on the Transaction Entity. The second tab is using the Name Entity, the third is using the Event and the fourth is using the Date Entity.

If I delete an entry from the Transaction tab, it deletes just that transaction which makes sense.

What I want is to be able to delete a person from the Name tab, or an event from the Event tab and have that cascading through the model of the app. So if Bob has multiple transactions, deleting him the transaction tab will delete that one transaction.

If I delete BOB from the name tab, it should deleting him from every event that he was part off with every date and Transaction.

The same applies for the events and dates.

EDIT: Update to include data model

Note: Year Entity is experimental and currently not being used enter image description here How would I go about doing something like this?

Thanks

like image 385
amitsbajaj Avatar asked Dec 11 '13 19:12

amitsbajaj


1 Answers

If you set the "Deletion Rule" for the "transactions" relationship from Person to Transaction to "Cascade", then deleting a person will automatically delete all related transactions.

like image 72
Martin R Avatar answered Sep 28 '22 12:09

Martin R