核心数据-删除规则问题
我对 coredata 中的删除规则有一个奇怪的问题。我的数据模型并没有那么复杂。我在这里仅详细说明元素之间的关系:
A
----------
has_many B (optional, delete rule : Cascade)
has_many C (optional, delete rule : Cascade)
B
----------
has C (optional, delete rule : Cascade)
inv_A (delete rule : Nullify)
C
----------
has B (optional, delete rule : Nullify)
inv_A (delete rule : Nullify)
当我删除 B 时,相关的 C 不会被删除。就像级联删除规则不起作用......
你有关于我做错了什么的提示吗?
感谢您的帮助
编辑
这只是一个重新获取问题。愚蠢的问题......永远不要忘记: A) 保存后重新读取库中的数据 B) 使用新的获取结果重新加载表(或使用 NSFetechedResultController)
I have a strange issue with delete rules in coredata. My data model is not so complicated. I detail here only relationships between elements :
A
----------
has_many B (optional, delete rule : Cascade)
has_many C (optional, delete rule : Cascade)
B
----------
has C (optional, delete rule : Cascade)
inv_A (delete rule : Nullify)
C
----------
has B (optional, delete rule : Nullify)
inv_A (delete rule : Nullify)
When I delete B, related C is not deleted. It is like cascade delete rule does not work...
Do you have an hint on what i am doing wrong ?
Thanks for your help
EDIT
It was just a refetch issue. Stupid question... Never forget to :
A) Refetch data in base after having saved
B) Reload table with that new fetch result (or use a NSFetechedResultController)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除规则始终适用于删除其他实体。因此,当您删除
C
对象时,has C
关系将确保B
也被删除。然而,相反,has B
关系仅设置为无效,因此这就是它的作用。为了澄清这种情况,请这样考虑:如果只有一种关系,比如 B 引用 C,这意味着 B 有一个类型为 C 的对象的字段。删除规则意味着解决以下问题:如果应该删除它指向的对象,应该如何处理该字段。
The delete rule always applies to the deletion of the other entity. So when you delete a
C
object, thehas C
relationship will make sure theB
is removed as well. The other way around, however, thehas B
relationship is only set to nullify so that’s what it does.To clarify the situation, think about it this way: if you only had one relationship, say B references C, meaning B has a field for an object of type C. The only sensible thing for a delete rule to mean is solving the question of what should be done with said field if the object it points to should be deleted.