0
votes

I have a case where i have three entities with one-to-many and one-to-many relationships:

Entity A (Entity B relationhip), 
Entity B (Entity A relationship, Entity C relationship),
Entity C (Entity B relationhip)

I have the reference of Entity A, and now i want to fetch all the related Entity C records. How can i do that? (with least amount of code)

Edit: Here's another way to put it.

Can we perform joins with CoreData. For example, (and this is a very crude example), We have a following entity-relationship:

Grand Parent  (1)---(m)  Parent
Parent        (1)---(m)  Child

So, now if i have "Albert" the Grand Parent, and i want to get all his grand children, how can i do that?

1

1 Answers

1
votes

In case someone else stumble across a similar situation, here's what worked for me:

NSArray *allFieldValues = [myEntityA valueForKeyPath:@"Entity B relationship.Entity C relationship.requiredFieldInEntityC"];

I was mainly interesting in reading the data of a single field in Entity C (that's linked to myEntityA object). The key concept here is that "don't think of CoreData as a 'database'".