Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should i use Cascade or nullify in Core Data for a relationship?

I have a one-to-many relationship and I am just trying to get a few things straight. When I set the relationship from A <-->> B everything is great and works out just the way I like. But when I want to change the relationship, clear everything out and add a couple different B's (than I did before), would I delete the relationship using nullify or cascade if I wanted it to be removed on both ends?

Also could any one give me a quick example of how I might go about this?

I was thinking something like [b setValue:nil forKey:myRelationship]

Is that anywhere close? Or do I need something else?

Thanks.

like image 954
James Dunay Avatar asked Jul 13 '11 17:07

James Dunay


People also ask

What is cascade delete rules in core data?

Cascade Delete RuleIf a note should always have a category, the deletion of a category should automatically delete the notes associated with that category.

Is it possible to have relationship in Coredata?

Inverse relationships enable Core Data to propagate change in both directions when an instance of either the source or destination type changes. Every relationship must have an inverse. When creating relationships in the Graph editor, you add inverse relationships between entities in a single step.

What is core data stack in iOS?

Overview. After you create a data model file as described in Creating a Core Data Model, set up the classes that collaboratively support your app's model layer. These classes are referred to collectively as the Core Data stack.


1 Answers

These relationship types apply when deleting managed objects themselves, not clearing out the relationships. So, if you have object 'a' linked to 'b', 'c', and 'd', then when you delete 'a':

  • if the relationship is 'cascade', 'b', 'c', and 'd' will all be deleted as well
  • if it's 'nullify', then just the relationship back to 'a' will be cleared on these objects.

In all cases, you can use [b setValue: nil for Key: myRelationship] to clear out the relationship on both sides.

like image 75
Ben Gottlieb Avatar answered Oct 15 '22 11:10

Ben Gottlieb