views:

19

answers:

1

Example: I have a Department and an Employee. Department has a Nullify relationship to many Employees, and an Employee has an inverse relationship to one Department.

Now I remove the relationship to an Employee. So lets say the Marketing Department doesn't link anymore to Joe Stevens.

1) Does Joe Stevens still link to the Marketing Department, when asking for his Department? Or is Core Data handling this automatically and also "nullifying" that?

2) Does it matter which delete rule is specified on the side of the Employee? Let's say that was Cascade. The Department removed the relationship to the Employee. I believe the delete rule of the Employee is not relevant in this case, right?

+1  A: 

The delete rule govern what happens to the object at the other end of the relationship when the object holding the rule itself is deleted.

So:

A<-(cascade)->>B
B<<-(nullify)->A

Deleting A causes all the deletion of all related B. However, deleting any single one B simply causes A to forget about that particular B.

So, the delete rule is always relevant to the object it is targeted at because the targeted object is the entire point of the delete rule. This is especially true when objects have multiple relationships.

A<-(cascade)->>B
B<<-(nullify)->A
C<--(cascade,required)-->>B

The C object will block the cascade deletion of any B objects it also holds regardless of what A wants. (A will nullify in that case.)

You should not think of delete rules in terms of actual programming but rather in terms of the real world system you are trying to model. Think about the relationship of the real system and then set the delete rules to mimic those. In this case we would mimic the actually organizational rules of the company.

TechZen
Great explanation. Should go into the apple docs ;)
dontWatchMyProfile