核心数据-删除规则问题

发布于 2024-11-03 14:35:25 字数 566 浏览 0 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仙女 2024-11-10 14:35:25

删除规则始终适用于删除其他实体。因此,当您删除 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, the has C relationship will make sure the B is removed as well. The other way around, however, the has 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文