实体之间的核心数据关系

发布于 2024-11-16 12:53:50 字数 291 浏览 3 评论 0原文

您好,我需要在我的应用程序中使用 coredata 关系。 coredata 关系对我来说是首要任务。请指导我。

我需要有 2 个实体“产品”和“评论”。对于单个产品,可以有多个评论。我有 3 个问题。

1)“产品”实体已经包含数据。我需要稍后将评论添加到“评论”实体。那么我如何连接这两个实体呢?两者之间唯一的共同点是“产品 ID”。

2)如果我删除一个产品,如何从“评论”实体中删除与其相关的所有评论。

3)我可以在不改变“产品”实体的情况下删除评论吗?

请帮助我。 提前致谢。

hi i need to use coredata relations in my app. coredata relations is first tym for me. kindly guide me.

i need to have 2 entities "Products" and "reviews". for a single product there can be multiple reviews. i have 3 questions.

1) "product" entity is already containgin data. i need to add reviews to "reviews" entity later only. so how do i connect both the entities? the only thing common between both is the "product id".

2) if i delete a product how to delete all the reviews related to it from "reviews" entity.

3) can i delete the reviews without altering "products" entity

kindly help me.
thanks in advance.

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

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

发布评论

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

评论(2

偏闹i 2024-11-23 12:53:50

产品和评论之间的关系是一对多的。因此,在两个实体之间创建关系,并将产品实体的删除规则设置为“级联”,这样当删除产品实体时,该产品对应的评论也会被删除。

The relationship between product and review is one to many. So create a relationship between the 2 entities, also set set the delete rule for product entity to “cascade”, so that when a product entity is deleted, the corresponding reviews for the products also gets deleted.

柏拉图鍀咏恒 2024-11-23 12:53:50

您必须为两个实体建立关系,如果您使用 NSArrayController 来管理对象上下文,则必须为 绑定内容集回顾它的关系。
那么您可以使用 NSarraycontroller 来控制添加为 review 的对象并删除它们,而不会影响 product 的对象。
此外,您必须将托管对象绑定为应用程序的委托来管理对象上下文。

You have to make relation for both entities and if you used NSArrayController to manage objected context you have to bind the Content set for the review to it's relation.
then you can use the NSarraycontroller to control the objects that you added as review and delete them without affecting product's objects.
Also,you have to bind managed objects as you app's delegate to manage Objected context.

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