1

如果我为 Parent - Child - Grandchild 设置了实体,并且它们之间存在一对多的关系,我知道我可以获取父母的所有 Child 实体或 Child 的所有 Grandchild 实体。

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

谢谢你的帮助!

4

1 回答 1

3

如果没有每个对多关系的反向关系,您将无法运行您描述的获取请求。但是,您应该对反向关系进行建模。CoreData 使用逆来保持对象图的一致性。鉴于to和to 的parent关系,你可以做ChildParentGrandchindChild

Pareint *aParent; //already initialized

NSSet *allGrandchildren = [aParent valueForKeyPath:@"children.@unionOfSets.children"];

Grandchild或对具有谓词的实体的获取请求:

[NSPredicate predicateWithFormat:@"parent.parent == %@", aParent];
于 2010-08-22T16:06:41.007 回答