将属性添加到多对多关系? [英] Adding properties to many to many relationship?

查看:127
本文介绍了将属性添加到多对多关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Core Data对数据库进行建模.我有2个处于多对多关系的实体.每个人可以有多个地址,并且每个人可以居住在每个地址上.

I have been using Core Data to model my database. I have 2 entities that are in many to many relationship. Each person can have many addresses, and on each address multiple persons can live.

现在,我想向此关系添加属性.例如,一个人-地址将带有标签家,其他人-地址将具有标签妈妈的位置.

Now i would like to add property to this relationship. For example one person - address will have label home, other person - address can will have label mama's place.

我不能在地址实体上添加此属性,因为相同的地址将为不同的人提供不同的标签.

I can't add this property on address entity, because same address will have different labels for different persons.

由于关系的建模方式类似于NSSet,因此我看不到有一种做我想做的事的方法.

Since relationships are modeled like NSSets, I don't see a way to do what I want.

这可以通过某种方式完成吗?

Can this be somehow done?

推荐答案

不可能直接将属性添加到多对多关系中.苹果公司推荐的方法(请参见基于关系建模"(《 CoreData编程指南》中的"")中,将中间关系实体替换为多对多关系,并在中间实体中添加了属性.您现有的每个实体都将与新实体建立一对多的关系.

It is not possible to add attributes to a many-many relationship directly. The Apple-recommended approach (see "Modelling a relationship based on its semantics" in the CoreData Programming Guide) is to replace the many-many relationship with an intermediate entity, to which you add the attributes. Each of your existing entities will have a one-many relationship with the new entity.

在您的情况下,您可能会遇到类似这样的情况:

In your case, you might have something like this:

Person     <--->> PersonAddressDetails <<--->    Address

然后可以将label属性添加到PersonAddressDetails实体.

You can then add the label attribute to the PersonAddressDetails entity.

这篇关于将属性添加到多对多关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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