如何在 XCode 中的 Core Data - 数据模型中表示外键关系
我正在制作我的数据模型,这是核心数据的全新内容。我有 33 个实体,它们之间几乎没有硬关系,但有很多外键关系。
我如何管理核心数据模型中不完全是一对多、一对一或多对多而是外键的关系?
例如,我有一个联系人实体,它与 contact_x_mail 有关系,同时 contact_x_mail 与包含所有电子邮件的邮件有关系。这种关系是一对多或多对多。但还有其他的,比如Institution(一个联系人可以有多个Institution)和Mail,这不是一对多或1-1的关系,Institution有一个ForeignKey_mail_id。
我如何表示外键关系?索引?
非常感谢,希望我的问题很清楚。
Totally new with Core Data, I'm making my data model. I have 33 entities, and few hard relationships between them but lots of Foreign-Key relationships.
How can I manage that relationships that are not exactly 1-many or 1-1 or many-many but are foreign keys in Core Data Model?
For ex., I have a Contact entity, which has a relationship with a contact_x_mail, and at the same time contact_x_mail has a relationship with Mail, that contains all emails. This relationships are 1-many or many-many. But there are others like Institution (a contact can have many Institutions) and Mail, that is not a 1-many or 1-1 relationship, Institution has a ForeignKey_mail_id.
How can I represent that foreign key relationships? Indexes?
Thank you very much, hope my question is clear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将 CoreData 视为 DBMS,但事实并非如此。您不需要设置外键来在 CoreData 中建立关系。如果您想将电子邮件分配给用户,您只需在两者之间创建关系,并且可以设置用户的属性“电子邮件”或电子邮件的“用户”属性。 foreignKey和链接都是由CoreData在后台完成的。
另一方面,根据定义,每个关系都是 1-1、1-* 或 -。我不确定还有其他选择...
当您在 CoreData 中创建关系时,您实际上是在为该项目创建新属性。这是一个例子:
设置这些就像这样简单:
希望这有助于澄清一些事情!阅读文档以确保 CoreData 适合您!
http://developer.apple.com/library/mac /documentation/Cocoa/Conceptual/CoreData/CoreData.pdf
You are thinking of CoreData in terms of a DBMS which it is not. You don't need to set up foreign keys to make relationships in CoreData. If you want to assign an email to a user you just create a relationship of between the two and you can set the attribute "email" of a user or the "user" attribute of an email. The foreignKey and linking is all done by CoreData in the background.
On another point, every relationship is by definition, 1-1, 1-*, or -. I'm not sure there is any other choice...
When you create relationships in CoreData you are effectively creating new attributes for this item. Here is an example:
Setting these is as simple as:
Hope this helps clear things up a bit! Read up on the documentation to make sure CoreData is right for you!
http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/CoreData.pdf