简体   繁体   English

可以包含可定制产品(RDMS)的订单的数据库架构

[英]Database schema for orders that can contain customizable product (RDMS)

I come from frontend background, so I apologize if this db question seems dumb. 我来自前端背景,因此对于这个数据库问题似乎很愚蠢,我深表歉意。

Say I have a database that handles orders of car and car accessories. 说我有一个处理汽车和汽车配件订单的数据库。 If Car is non-customizable, then everything is easy-peasy. 如果Car是不可自定义的,那么一切都很简单。 For every order, we simply need to associate the OrderId with the Car 's ProductId . 对于每个订单,我们只需要将OrderIdCarProductId关联。 But a Car is a Product that can contain one or more Product like navigation, seat heater, etc. And users can also purchase those accessories Product separately. Car是一个Product ,可以包含一个或多个Product像导航,座椅加热等,而用户也可以购买这些配件Product分开。

How should we handle this best? 我们应该如何最好地应对? Should every Product a user orders be given a unique ProductOrderId in the order table and if that Product can contain another Product , then we put it in a table that associates ProductOrderId with ProductId ? 是否应该在订单表中为用户订购的每个Product赋予唯一的ProductOrderId ,并且该Product可以包含另一个Product ,那么我们将其放在将ProductOrderIdProductId关联的表中吗?

If we do this, would the db grow out of control? 如果这样做,数据库是否会失去控制? Seems a little inefficient to me. 在我看来似乎效率低下。 I have a feeling there is a better way. 我觉得有更好的方法。

If you look at how complex products are typically billed, the main item and each of its options are treated as separate line items in the bill of sale. 如果您查看复杂产品通常是如何计费的,则主要项目及其每个选项在销售清单中都被视为单独的行项目。 In that kind of scenario, a car is a product and each of its accessories are also products. 在这种情况下,汽车是一种产品,其每个配件也是产品。 You can have an involuted relationship on product to indicate which accessories go with which type of car. 您可以在product上具有复杂关系,以指示哪种附件与哪种类型的汽车配套。

Your data model for this scenario would look something like this: 您在这种情况下的数据模型如下所示:

在此处输入图片说明

Alternatively, you could have a scenario where you want a level of abstraction such that your bill of sale contains only a single item, being a fully accessorized car. 或者,您可能会遇到这样一种情况,您需要一个抽象级别,以便您的销售清单仅包含一个项目,即完全装饰的汽车。 That requires the order item to become more like a header in a bill of materials, like so: 这要求订单项变得更像物料清单中的抬头,如下所示:

在此处输入图片说明

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

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