核心数据中间实体 [英] Core Data InterMediate Entity

查看:140
本文介绍了核心数据中间实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有3个实体


  1. 父亲---->姓名

  2. 儿子 - - >姓名

  3. FatherSon ----> ID

关系


  1. 父亲--- >> fatherson

  2. 儿子--->儿子

  3. FatherSon - >父亲---- >>父亲,儿子----> sonfather

我用过中间体表拯救父与子之间的关系。父子之间没有直接关系。

I have use intermediate table to save relations between Father and Son. There is no direct relation between Father and Son.

现在,

我能够将父子关系保存到FatherSon Entity中。

I am able to save the relation of father and son into FatherSon Entity.


  1. 我的主要问题是使用FatherSon的关系从Son实体访问Son名称。

  2. 要访问使用FatherSon关系的父实体父名。

所有信息都显示在tableview中。

All the information is to shown into tableview.

当我在tableview中选择父名时。 didselect事件必须进入详细信息视图
并显示父亲与之相关的儿子姓名列表以及儿子的相同列表。

When i select Father name in the tableview. The didselect event has to take to details view and show the list of Son name that Father is related to and the same for Son.

推荐答案

我不确定我是否100%理解你的问题,但现在就去了。 。 。

I'm not sure I 100% understand your question but here goes . . .

在核心数据术语中,我假设你有类似的东西:

In Core Data terms I assume that you have something like :


  • 父是一个实体,有一个名为的父属

  • 父亲是一个实体,有一个名为'son'的属性和一个名为'father'的属性'

  • Son是一个实体,有一个名为'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!)

这篇关于核心数据中间实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆