mysql - 如何构建具有多种类型项目(服务、零件和保险等)的模式
问题描述
我需要为一个涉及两件事的项目设计架构。
- 提供服务(与车辆相关)
- 也卖保险,备件,也许其他类型也可以稍后添加
对于每种类型的项目订单处理可能不同,所以我需要在订单处理之前知道项目类型。
我还需要知道购物车中的物品类型,以便我可以相应地加入该表。
我还有一个UsedCoupons
包含item_id
and的表coupon_id
。这里我还需要知道项目类型。和
_cartItems
orders
到目前为止,我可以想到两种方法,但我认为它们都不正确。我将在下面解释。
1.每个项目都会有表格insurances
spareParts
services
等。还有
一个表格来存储类型。
itemTypes
--------------------
id
type_name
现在usedCoupons
,cartItems
并且orders
将包含一个item_type_id
with item_id
。
但是在这里,我将无法加入表格。因为它们取决于item _types
2.仅放入item_type_id
每个项目:insurances
等spareParts
services
,
并且仅item_id
放入usedCoupons
、cartItems
< 和orders
表格。
但在这种情况下,我必须为所有服务创建父级。
itemParent
---------------------
id
name
description
item_id
item_type_id
现在再次加入在这里也很痛苦。
我将加入cartItems
to items
,但有关详细信息,请在加入特定表之前再次查找它的类型。
对于这两种方法,我认为它们都不正确。如果有人可以提供帮助,可能还有其他解决方案。
解决方案
基于这个答案,我想我可以使用下面的架构
Items
--------------------
item_id (primary key)
name
description
price
item_type_id ( here foreign key, primary key for item types)
//it contains all the shared attributes in each type of items
Services
-----------------------
service_id (primary key)
item_id (foreign key, primary for Items)
....other attributes
SpareParts
---------------------
spare_part_id (primary_key)
item_id (foreign key, primary for Items)
....other attributes
Insurances
-----------------------
insurance_id (primary_key)
item_id (foreign key, primary for Items)
....other attributes
//Finally have a ItemTypes tables
ItemsTypes
---------------------
item_type_id (primary key)
item_type ( varchar, name of the item type : service, insurance)
现在,UsedCoupon
CartItems
并且Orders
将只有item_id
但我仍然需要在这里有人的关注,如果有人可以帮助我将不胜感激。
推荐阅读
- javascript - 没有 jquery 的 django 错误 ajax CSRF 令牌丢失或不正确
- python - 训练不断停止。元组错误。(Tensorflow Object_detection API)
- swift - 如何在 Mac 上实现 VoiceOver 的accessibilityCustomActions?
- jenkins - Jenkins 从站设置因私钥身份验证而失败
- javascript - JavaScript 函数式编程:如何处理 fetch(对于管道)
- python - 附加 Numpy 数组
- javascript - Javascript数组和正确的anwser问题
- python - 如何训练 CNN 解码多长度验证码
- sqlite - sqlite 是否支持在 DELETE 子句中加入 JOIN?
- for-loop - 如何处理迭代器的类型?