开发者

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 开发者_StackOverflowme, and how should I respond?


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.


Deny If there is at least one object at the relationship destination, then the source object cannot be deleted. For example, if you want to remove a department, you must ensure that all the employees in that department are first transferred elsewhere (or fired!) otherwise the department cannot be deleted.

Nullify Set the inverse relationship for objects at the destination to null. For example, if you delete a department, set the department for all the current members to null. This only makes sense if the department relationship for an employee is optional, or if you ensure that you set a new department for each of the employees before the next save operation.

Cascade Delete the objects at the destination of the relationship. For example, if you delete a department, fire all the employees in that department at the same time.

No Action Do nothing to the object at the destination of the relationship. For example, if you delete a department, leave all the employees as they are, even if they still believe they belong to that department.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜