如果我为 Parent - Child - Grandchild 设置了实体,并且它们之间存在一对多的关系,我知道我可以获取父母的所有 Child 实体或 Child 的所有 Grandchild 实体。
是否可以运行获取给定父级的所有 Granchild 实体的提取?
谢谢你的帮助!
如果我为 Parent - Child - Grandchild 设置了实体,并且它们之间存在一对多的关系,我知道我可以获取父母的所有 Child 实体或 Child 的所有 Grandchild 实体。
是否可以运行获取给定父级的所有 Granchild 实体的提取?
谢谢你的帮助!
如果没有每个对多关系的反向关系,您将无法运行您描述的获取请求。但是,您应该对反向关系进行建模。CoreData 使用逆来保持对象图的一致性。鉴于to和to 的parent
关系,你可以做Child
Parent
Grandchind
Child
Pareint *aParent; //already initialized
NSSet *allGrandchildren = [aParent valueForKeyPath:@"children.@unionOfSets.children"];
Grandchild
或对具有谓词的实体的获取请求:
[NSPredicate predicateWithFormat:@"parent.parent == %@", aParent];