开发者

Coredata, Specify different value for each each entity relationship, Xcode

开发者 https://www.devze.com 2023-03-28 11:37 出处:网络
I have a relationship between two entities like so. A<<----->>B. A = Employees B = Areas An Employee can belong to many Areas and an Area can have many Employees. I would like to add a zone

I have a relationship between two entities like so. A<<----->>B.

A = Employees

B = Areas

An Employee can belong to many Areas and an Area can have many Employees. I would like to add a zone each employee is supposed to be at for each area... (can be as simple as a number)

So say in area1, employee1's zone might = 4, but in area2, employee1's zone would = 2.

Could anyone give me any thoughts on how i might do this? I'm just a little confused about the architecture of something like this.

开发者_开发百科

I previously had it to where it was just A<<----->B which made things much more simple because i just had a zone attribute for each employee that i just changed, but with a many-to-many it complicates things a bit.

Thanks.


You can create a third entity zone Z with a one-to-many relationship to area B. Each area B can have several zones Z, but each zone Z belongs to exactly one area B.

Z<<----->B

Now each employee A has one and exactly one zone assigned for each area. So you need a many-to-many relationship between zone Z and employee A. One zone Z in an area B can have several employees A assigned to it; one employee A has several zones (one for each area B).

A<<----->>Z

That should work. Now it is enough to know a zone Z of an employee A - you can look up the corresponding area B.

0

精彩评论

暂无评论...
验证码 换一张
取 消