Objective-c – Xcode consistency error: Setting the No Action Delete Rule… is an advanced setting


After creating a data model in Xcode, it's throwing the following error for each of the object relationships:

Consistency Error:
Setting the No Action Delete Rule on [object relationship] is an advanced setting

What is Xcode trying to tell me, and how should I respond?

Best Solution

Core Data uses inverse relationships and delete rules to keep the object graph consistent

Let's say you have A.foo <1—1> B.bar and do a.foo = b. This automatically (effectively) performs b.bar = a.

Now let's say you [b delete]. With the "nullify" rule, effectively does b.bar.foo = nil. With "cascade", it does [b.bar delete]. With "no action", it does nothing; a.foo is now a "dangling Core Data object reference".

It's not really a dangling pointer; standard memory management rules mean that b will still exist in memory while a points to it (until a turns into a fault), but a.foo will forever refer to a deleted object, which raises an exception when you try to access its properties. I'm not sure what happens when you save and re-fetch a either.

With a many-to-many relationship, it gets more complicated. Implementation details: The relationship appears to be "owned" by one of the entities, and is only saved when that entity is saved (I hit this bug when trying to set up a relationship across different MOCs: the MOC that saved didn't own the updated entity, so the relationship was never saved). Clearly when you delete both a and b, the relationships should also be removed, so one assumes that the relationship disappears only one of them is removed (but you don't know which one!).

You probably want Nullify or Cascade. I never use Cascade because I can never remember which direction the cascading happens in.