There are 3 entity
- Father ---->Name
- Son ---->Name
- FatherSon---->ID
Relationships
- Father --->>fatherson
- Son --->sonfather
- FatherSon-->father---->>fatherson, son---->sonfather
I have use intermediate table to save relations between Father and Son. There is no direct relation between Father and Son.
Now,
I am able to save the relation of father and son into FatherSon Entity.
- My main problem is to access a Son name from Son entity using the relation of FatherSon.
- TO access Father name from Father entity using the relation of FatherSon.
All the information is to shown into tableview.
When i select Father name in the tableview. The didselect event has to take to deta开发者_开发百科ils view and show the list of Son name that Father is related to and the same for Son.
I'm not sure I 100% understand your question but here goes . . .
In Core Data terms I assume that you have something like :
- Father is an entity with a property called
fatherSons
- FatherSon is an entity with a property called 'son' and a property called 'father'
- Son is an entity with a property called 'fatherSon'
So, to get from one to the other should be simple :
// We start with a father
Father *father = <get the father from core data>
// Get a set of all the sons that father ]has
NSSet *sons = father.fatherSons;
// Output each son and his father
for (Son *son in sons)
NSLog(@"%@ has father %@", son, son.fatherSon.father);
So in your table view you would use
son.fatherSon.father
to display the father of a particular son and
father.fatherSons
to get the list of all the sons given a particular father
Just out of interest . . .
Why do you have to use an intermediate table - surely it should be
Father has many Sons
Son has one Father
(well, technically I'd have Child instead of Son but hey, I don't know what your app is!)
精彩评论