核心数据中间实体

发布于 2024-12-02 14:25:37 字数 552 浏览 1 评论 0原文

有 3 个实体

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

关系

  1. Father --->>fatherson
  2. Son --->sonfather
  3. FatherSon-->ID父亲---->>父亲,儿子---->儿子父亲

我使用中间表来保存父亲和儿子之间的关系。父与子之间没有直接关系。

现在,

我可以将父子关系保存到FatherSon实体中。

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

所有信息都显示在表格视图中。

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

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 details view
and show the list of Son name that Father is related to and the same for Son.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最后的乘客 2024-12-09 14:25:37

我不确定我是否 100% 理解你的问题,但这里是。 。 。

在核心数据术语中,我假设您有类似的内容:

  • 父亲是一个实体,具有名为 fatherSons 的属性
  • FatherSon 是一个实体,具有名为“儿子”的属性和名为“父亲”的属性
  • 儿子是一个实体具有名为“fatherSon”的属性

因此,从一个到另一个应该很简单:

// 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);

因此,在表视图中,您将使用

son.fatherSon.father

显示特定儿子的父亲并

father.fatherSons

父亲的所有儿子的列表


获取给定特定 出于兴趣。 。 。

为什么你必须使用中间表 - 当然应该是

Father has many Sons
Son has one Father

(好吧,从技术上讲,我有 Child 而不是 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!)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文