iPhone Core Data获得了孙子

时间:2010-08-22 15:49:40

标签: iphone core-data nsfetchrequest

如果我为Parent - Child - Grandchild设置了实体,并且他们之间建立了一对多关系,我知道我可以为父母或所有孙子实体获得所有子实体。

是否可以运行一个fetch来获取给定Parent的所有Granchild实体?

感谢您的帮助!

1 个答案:

答案 0 :(得分:3)

如果没有针对每个to-many关系的反向关系,则不能运行您描述的获取请求。但是,您应该建立反向关系的建模。 CoreData使用反转来维护对象图的一致性。鉴于从parentChildParentGrandchind的{​​{1}}关系,您可以

Child

或带有谓词的Pareint *aParent; //already initialized NSSet *allGrandchildren = [aParent valueForKeyPath:@"children.@unionOfSets.children"]; 实体的获取请求:

Grandchild