核心数据:如何删除关系中的实体

发布于 2024-08-24 19:17:16 字数 112 浏览 8 评论 0原文

我的 iPhone 上有一个复杂的核心数据图。用户实体具有许多其他实体,这些实体彼此相关且具有多种关系等...

我的问题是,当我删除用户实体时,如何删除所有相关实体。

提前致谢!

I have a complex Core Data graph on the iPhone. A user entity has a lot of other entities which are related one to the other with multiple relationships etc...

My question is how can I delete all the related entities when I delete the user entity.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

泛滥成性 2024-08-31 19:17:16

在您的用户实体中,将每个关系删除规则设置为“级联”。

另请参阅此答案< /a> 到 iPhone 核心数据:级联删除跨多对一关系

In your User entity, set each relationship delete rule to "cascade".

Also, see this answer to iPhone Core Data: Cascading delete across a many-to-one relationship.

り繁华旳梦境 2024-08-31 19:17:16

您将删除规则设置为用户实体侧进行级联。当删除用户实体时,与删除规则级联有关系的所有其他实体也将被删除。如果它们同样与其他实体有关系,您也可以为这些关系设置删除规则以进行级联。当您删除最顶层的节点时,这将删除整个逻辑树。

例如,

user--(phoneNumbers,Cascade)->>phoneNumber
user<--(user,nullify)--phoneNumber

删除用户会触发删除phoneNumber,但删除phoneNumber 只会使与用户的关系无效。用户实体不受影响。

如果你有一棵树...

user--(phoneNumbers,Cascade)->>phoneNumber--(phoneNumbers,Cascade)->>areaCodes

...然后删除用户会删除其所有phoneNumbers并删除phoneNumber会导致删除所有区号

You set the delete rule on the user entity side to cascade. When the user entity is deleted, all the other entities held in relationships with the delete rule cascade will be deleted as well. If they likewise have relationships with other entities you can set the delete rule for those relationships to cascade as well. This will delete and entire logical tree when when you delete the top most node.

E.g

user--(phoneNumbers,Cascade)->>phoneNumber
user<--(user,nullify)--phoneNumber

Deleting user triggers the deletion of phoneNumber but deleting phoneNumber merely nullifies the relationship with user. The user entity is otherwise unaffected.

If you have a tree...

user--(phoneNumbers,Cascade)->>phoneNumber--(phoneNumbers,Cascade)->>areaCodes

...then deleting user deletes all its phoneNumbers and deleting a phoneNumber causes the deletion of all its areaCodes

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