Bartłomiej Semańczyk
Bartłomiej Semańczyk

Reputation: 61774

How to interpret delete rule in Core data in XCode?

I have example as it is on the image below: enter image description here

How should I understand this?

What happen to PBOLocation when I delete PBORole? or
What happen to PBORole when I remove PBOLocation? or
What happen to PBORole when I remove relationship between them? or
What happen to PBOLocation when I remove relationship between them?

Upvotes: 0

Views: 168

Answers (1)

Mundi
Mundi

Reputation: 80265

Your delete rule in the image is Nullify. Therefore, "nothing" will happen.

When you delete Role, location.roles will be reduced by one.
When you delete Location, role.location will be nil.
When you you remove the relationship by setting role.location = nil, location.roles will be reduced by one.
When you reduce a role from location.roles, role.location will be nil.

If, however you choose Cascade as the delete rule, it becomes more interesting:

When you remove the relationship from either direction, the same happens as described above. If you set the Cascade rule for the roles relationship on Location, deleting Location will delete all Role objects in roles.
If you set the Cascade rule for the location in Role, deleting Role will delete its location (and if the reverse relationship rule is Cascade as in the rule above, all other roles will be deleted as well).

Read all about it in the Core Data Programming Guide under Relationship Delete Rules.

Upvotes: 1

Related Questions