Core Data - Entity Relationships Not Working as expected
Posted
by slimms
on Stack Overflow
See other posts from Stack Overflow
or by slimms
Published on 2010-06-17T15:35:19Z
Indexed on
2010/06/17
16:03 UTC
Read the original article
Hit count: 405
I have set up my data model in xcode like so
EntityA
AttA1 AttA2
EntityB
AttB1 AttB2 AttB3
I then set up the relationships
EntityA
Name: rlpToEntityB
Destination: EntityB
Inverse: rlpToEntityA
To Many: Checked
EntityB
Name: rlpToEntityA
Destination: EntityA
Inverse: rlpToEntityB
To Many: UnChecked
i.e. relationship between the two where Each one of EntityA can have many EntityB's
It is my understanding that if i fetch a subset of EntityB's I can then retrieve the values for the related EntityA's.
I have this working so that i can retrieve the EntityB values using
NSManagedObject *objMO = [fetchedResultsController objectAtIndexPath:indexPath];
strValueFromEntityB = [objMO valueForKey:@"AttB1"];
However, if I try to retrieve a related value from EntityA by doing the following
strValueFromEntityA = [objMO valueForKey:@"AttA1"];
I get the error "The entity EntityB is not Key value coding-compliant for the key Atta1"
Not surprisingly i suppose if i switch things around to fetch from EntityA i cannot access attributes of EntityB So it appears the defined relationshipare being ignored.
Can anyone spot what i am doing wrong?
I confess im very new to iPhone programming and especially to Core Data so please go easy on me and provide verbose explanations or point me in the direction a specific resource. I have downloaded the apple sample apps (Core Data Books, Top Songs and recipes) but I still can't work this out.
Thanks in advance, Nev.
© Stack Overflow or respective owner