数据库设计以避免冗余问题:使用约定还是不同的设计?
注意:图像可点击以允许缩放
我对这个数据库设计有问题,我有不同的解决方案,但没有一个让我足够满意。
该软件是关于产品的配置器。您可以使用此配置器选择所有会增加价格的附加功能。
这是我应该向用户呈现的数据。给我带来问题的是,有两种类型的附加功能:
- 这种类型的附加功能没有价格,合并在一个包中,该包的所有附加功能都有价格。 (放松[A123]是一个带有价格的包裹示例,第一张图片)
- 这种类型的额外物品有价格,并且它的包裹没有任何价格,因为它们没有绑定在包裹中(供水是包裹的示例)没有价格)
这是我目前的设计,我不满意:
(忽略 ExtrasCategory,它只是对额外内容进行分组)
最大的问题是每个 Extra(现在的类)都属于一个包,即使它没有价格。
但是,每个套餐的每艘船的价格可能不同,所以我需要设置不同的价格。
我想要这样的东西:
- 每个额外都有一个“基本”包。
- 如果套餐有价格,我们为每艘船设置不同的价格
- 如果套餐没有价格,我们可以使用 Extra 的“基本”套餐
但是这样我就有了冗余:Extra 有一个套餐,BoatExtra (额外的价格)有一个 BoatExtrasPackage,所以我们有 2 次对包的引用
我该如何解决这个设计问题?
编辑 1: 好的,我创建了一张图像,可以更好地解释我想要的内容。如果 BoatExtra 没有,我想要一个额外的“默认套餐”(按额外费用)。
Note: Images are clickable to allow zoom
I have problem with this database design, I have different solution but none of them satisfact me enough.
The software is about a configurator for a product. You can choose with this configurator all the extras that will increase the price.
This is the data that I should present to the user. What's giving me problems is the fact that there are 2 type of extras:
- This type of extra doesn't have a price, is merged inside a package which has a price for all its extras. (Relax [A123] is an example of package with price, first image)
- This type of extra has a price and its package doesn't have any price, because they aren't boundled in the package (Water supply is an example of package without price)
Here is my current design, which I'm not satisfact with:
(Ignore ExtrasCategory which is only to group up extras)
The biggest problem is that each Extra (the class now) belongs to a package, even if it doesn't have a price.
However, each Package may have a price different for each Boat, so I need to set different prices.
I want something like this:
- Each Extra has a "basic" Package.
- If the Package has a price, we set it differently for each boat
- If the Package doesn't have a price, we can use the "basic" Package of the Extra
However in this way I have redundancy: Extra has a Package, BoatExtra (an extra with price) has a BoatExtrasPackage and so we have 2 times a reference to a package
How can I solve this design issue?
Edit 1: Ok I've created an image which explains better what I want. I want a "default package" for an extra (on a per-extra basis), if the BoatExtra doesn't have one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的设计中有冗余,即:代码和名称。如果我正确理解您的系统,我会按照附件进行操作。
You have redundancy in your design ie: code and name. I would do it as attached if I understand properly your system.
看来问题是我想尽量减少空间消耗,而不是做出好的设计。当我明白我正在这样做(对我来说这是错误的)之后,我想出了一种完全不同的设计,它比之前的设计更好并解决了我的问题。
我显然需要构建更多的包,但这就是逻辑想要的
Seems the problem is that I want to minimize space consumption, not make a good design. After I understood I were doing this (which for me it's wrong) I came up with a totally different design which is better than the previous one and fixed my problem.
I obviusly need to build more packages but this is what the logic wants