2017-10-11 33 views
1

我有一个实体的集团和与人的关系:如何建立与它有两种以上关系的实体的反向关系?

Group: 

Group.leader -> Person (To One) 
Group.looser -> Person (To One) 
Group.others ->> Person (To Many) 

leaderlooserothers集我可以有不同的Person实体。同一人可能是leader在一个组中,looser在第二个并且在others中出现在第三组中。

Person实体

我有一对多的关系groups应连接

Person: 

Person.groups ->> Group (should be enough but warnings) 

因为我只能让一个反比关系,我总是 将有一个警告“东西应该有逆”

如何处理这样的关系?

或者: 我有实体Cube,PlanLineCube有关系x,y,z,平面xy,线只是x。我需要在它们之间分享一些值,有时甚至是混合的:

Cube: 
Cube.x --> Value 
Cube.y --> Value 
Cube.z --> Value 

Plane: 
Cube.x --> Value 
Cube.y --> Value 

Line: 
Cube.x --> Value 

Value: 
Value.counted -->> Line.x or Line.y, Plane.x, Cube.x, y, z, SomeAnotherEntity.neededValue 

回答

1

Apple建议每个关系都应该有相反的关系。在你的情况,那将意味着Person实体将有三个关系:

Person.groupsLed ->> Group (to many) // "groups where this Person is leader" 
Person.groupsLost ->> Group (to many) // "groups where this person is the looser" 
Person.otherGroups ->> Group (to many) // "other groups with this person as a member" 

这似乎相当复杂。一个替代方案是将三个关系与中间实体折叠成一个(每个PersonGroup)(Ranking):

Group.rankings ->> Ranking (to many) // "the ranking of people for this group" 
Person.rankings ->> Ranking (to many) // "the ranking of this person in different groups" 

在每种情况下的逆。将酮:

Ranking.person -> (Person) (to one) // "the person for this ranking" 
Ranking.group -> (Group) (to one) // "the group for this ranking" 

然后,您可以向Ranking实体添加属性以指示领导者/疏散者/其他人。这可能是一个简单的字符串属性rank,它采用值“leader”,“looser”或“other”或等效整数枚举。要管理GroupPerson之间的关系,请添加或删除Ranking对象。所有这一切的一个不利之处是,找到领导者或宽松者需要过滤排名,但它确实给了你一定程度的灵活性。

+0

这真的很好的答案。但是很难控制逻辑和可能的错误。我会尝试。谢谢! –

+0

但是在更简单的情况下该怎么做:假设我有一个实体Position,它与实体Value具有一对一的关系x和y。我可以将价值一对多连接到位置,但是......警告当然。在更糟糕的情况下,我想使用一些值不仅仅是位置,而是颜色(其中三个)或距离(只有一个)? –

+0

我不确定我的理解 - 你能否更新你的问题以提供更多的细节? – pbasdf