iPhone核心数据得到孙子

发布于 2024-09-15 11:08:54 字数 120 浏览 2 评论 0原文

如果我为“父-子-孙”设置了实体以及它们之间的一对多关系,我知道我可以获取父级的所有子实体或子级的所有孙子实体。

是否可以运行获取来获取给定父级的所有 Granchild 实体?

感谢您的帮助!

If I have entities set up for Parent - Child - Grandchild and one to many relations between them I know I can then get all the Child entities for a parent or all the Grandchild Entities for a Child.

Is it possible to run a fetch that will get all the Granchild entities for a given Parent?

Thanks for any help!

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

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

发布评论

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

评论(1

神也荒唐 2024-09-22 11:08:54

如果没有每个对多关系的反向关系,您将无法运行您所描述的提取请求。但是,您应该对逆关系进行建模。 CoreData 使用逆来保持对象图的一致性。给定从 ChildParentGrandchindChildparent 关系,您可以这样做

Pareint *aParent; //already initialized

NSSet *allGrandchildren = [aParent valueForKeyPath:@"[email protected]"];

或带有谓词的 Grandchild 实体上的提取请求:

[NSPredicate predicateWithFormat:@"parent.parent == %@", aParent];

Without inverse relationships for each to-many relationship, no you cannot run a fetch request that you describe. However, you should be modeling the inverse relationships. CoreData uses the inverses to maintain consistency of the object graph. Given parent relationships from Child to Parent and Grandchind to Child, you can do

Pareint *aParent; //already initialized

NSSet *allGrandchildren = [aParent valueForKeyPath:@"[email protected]"];

or a fetch request on the Grandchild entity with predicate:

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