简体   繁体   English

MySQL-EER图表-组必须具有某种类型的成员

[英]MySQL - EER Diagram - A group must have certain type of member

I'm trying to create a database, one part of my database is that, there are different Groups and there are Members in them. 我正在尝试创建一个数据库,我数据库的一部分是,有不同的组,其中有成员。 There are some requirements, a group MUST have a member wearing red cloth, and a member wearing yellow and a member wearing blue. 有一些要求,一个组必须有一个穿着红色衣服的成员,一个穿着黄色衣服的成员和一个穿着蓝色衣服的成员。 It can have members wearing other colour but is optional for the group to exist. 它的成员可以穿着其他颜色,但是对于组的存在是可选的。

I'm not sure how can I do it in an elegant way. 我不确定该如何优雅地进行操作。 This is my current concept: 这是我目前的概念:

我的EER

Your current concept is wrong. 您当前的概念是错误的。 It seems to imply that "a group has one or more members", "each member is wearing red", "each member is wearing blue", "each member is wearing yellow", and "each member is zero or more members wearing anything". 似乎暗示“一个组有一个或多个成员”,“每个成员穿红色”,“每个成员穿蓝色”,“每个成员穿黄色”和“每个成员是零个或多个穿任何东西的成员” ”。

A more correct solution would be the following (please excuse my short-hand notation, it's just quickly mashed up in Visio): 下面是一个更正确的解决方案(请原谅我的简写形式,它很快就在Visio中融合了起来):

在此处输入图片说明

Group is now connected directly to the sub-types of Member . 现在, 直接连接到Member子类型 Each member is either a member wearing red, a member wearing blue, a member wearing yellow, or a member wearing something else. 每个成员可以是一个成员穿红色,穿蓝色的成员,身穿黄色的成员,否则一员穿的东西。 The common attributes are in the Member table. 常用属性在“ 成员”表中。

As you can see, it's still not a very elegant as a DB solution. 如您所见,作为数据库解决方案,它仍然不是一个很好的解决方案。 As Strawberry noted in the comments of OP, this kind of logic should probably be implemented at the application layer rather than in DB. 正如Strawberry在OP的评论中指出的那样,这种逻辑可能应该在应用程序层而不是DB中实现。 In that case you could have a simple two-table solution with Group and Member , an attribute for Colour in Member , and somewhere in your application a rule that states that a group is only valid if it has these certain members. 在这种情况下,你可以有集团会员会员的颜色属性的两个表的简单解决方案,并在某处你的应用程序,指出一组是唯一的,如果它有这些某些成员有效的规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM