Adding properties to many to many relationship?

笑着哭i 提交于 2019-12-11 07:08:46

问题


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.

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

Can this be somehow done?


回答1:


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

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



来源:https://stackoverflow.com/questions/47225873/adding-properties-to-many-to-many-relationship

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!