开发者

Core Data InterMediate Entity

开发者 https://www.devze.com 2023-03-31 13:37 出处:网络
There are 3 entity Father---->Name Son---->Name FatherSon---->ID Relationships Father --->>fatherson Son--->sonfather

There are 3 entity

  1. Father ---->Name
  2. Son ---->Name
  3. FatherSon---->ID

Relationships

  1. Father --->>fatherson
  2. Son --->sonfather
  3. 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.

  1. My main problem is to access a Son name from Son entity using the relation of FatherSon.
  2. 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!)

0

精彩评论

暂无评论...
验证码 换一张
取 消