Xcode 一致性错误:设置无操作删除规则...是一项高级设置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5629481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:47:59  来源:igfitidea点击:

Xcode consistency error: Setting the No Action Delete Rule... is an advanced setting

iphoneobjective-cxcodecore-datadata-modeling

提问by Dan

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

在 Xcode 中创建数据模型后,它为每个对象关系抛出以下错误:

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?

Xcode 想告诉我什么,我应该如何回应?

回答by tc.

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

Core Data 使用逆关系和删除规则来保持对象图的一致性

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

假设您有 A.foo <1—1> B.bar 并执行a.foo = b. 这会自动(有效)执行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.foois now a "dangling Core Data object reference".

现在让我们说你[b delete]。使用“无效”规则,可以有效地执行b.bar.foo = nil. 有了“级联”,它确实如此[b.bar delete]。使用“no action”,它什么都不做;a.foo现在是一个“悬空的核心数据对象引用”。

It's not really a dangling pointer; standard memory management rules mean that bwill still exist in memory while apoints to it (until aturns into a fault), but a.foowill 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 aeither.

它并不是真正的悬空指针;标准内存管理规则意味着ba指向它时仍将存在于内存中(直到a变成错误),但a.foo将永远引用已删除的对象,当您尝试访问其属性时会引发异常。我不确定当你保存和重新获取时会发生什么a

With a many-to-many relationship, it gets more complicated. Implementation details: The relationship appears to be "owned" by oneof 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 bothaand 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!).

对于多对多关系,它变得更加复杂。实施细节:该关系似乎是由其中一个实体“拥有”的,并且仅在该实体被保存时才被保存(我在尝试跨不同 MOC 建立关系时遇到了这个错误:保存的 MOC 并不拥有更新的实体,因此从未保存关系)。很显然,当你删除这两个ab的关系也应该去掉,这样一个假设,只有其中一个被删除的关系消失(但你不知道哪一个!)。



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

您可能想要 Nullify 或 Cascade。我从不使用 Cascade,因为我永远记不起级联发生在哪个方向。

回答by Daniel

DenyIf 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.

拒绝如果关系目的地至少有一个对象,则无法删除源对象。例如,如果你想删除一个部门,你必须确保该部门的所有员工首先被转移到其他地方(或解雇!),否则该部门无法删除。

NullifySet 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.

Nullify将目标对象的逆关系设置为空。例如,如果您删除一个部门,则将当前所有成员的部门设置为空。只有当员工的部门关系是可选的,或者如果您确保在下一次保存操作之前为每个员工设置一个新部门时,这才有意义。

CascadeDelete 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 ActionDo 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.

无操作对关系目标处的对象执行任何操作。例如,如果您删除一个部门,让所有员工保持原样,即使他们仍然相信自己属于该部门。