views:

21

answers:

1

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!

+3  A: 

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];
Barry Wark
Thanks for that!
Fogmeister