实体之间的核心数据关系
您好,我需要在我的应用程序中使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
产品和评论之间的关系是一对多的。因此,在两个实体之间创建关系,并将产品实体的删除规则设置为“级联”,这样当删除产品实体时,该产品对应的评论也会被删除。
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.
您必须为两个实体建立关系,如果您使用 NSArrayController 来管理对象上下文,则必须为
绑定内容集
回顾它的关系。那么您可以使用 NSarraycontroller 来控制添加为
review
的对象并删除它们,而不会影响product
的对象。此外,您必须将托管对象绑定为应用程序的委托来管理对象上下文。
You have to make
relation
for both entities and if you usedNSArrayController
to manage objected context you have to bind theContent set
for thereview
to it's relation.then you can use the NSarraycontroller to control the objects that you added as
review
and delete them without affectingproduct'
s objects.Also,you have to bind managed objects as you app's delegate to manage Objected context.