首页 > 解决方案 > 如何构建具有多种类型项目(服务、零件和保险等)的模式

问题描述

我需要为一个涉及两件事的项目设计架构。

  1. 提供服务(与车辆相关)
  2. 也卖保险,备件,也许其他类型也可以稍后添加

    对于每种类型的项目订单处理可能不同,所以我需要在订单处理之前知道项目类型。

    我还需要知道购物车中的物品类型,以便我可以相应地加入该表。

    我还有一个UsedCoupons包含item_idand的表coupon_id。这里我还需要知道项目类型。和
    _cartItemsorders

到目前为止,我可以想到两种方法,但我认为它们都不正确。我将在下面解释。

1.每个项目都会有表格insurances spareParts services等。还有
一个表格来存储类型。

itemTypes
--------------------
id
type_name

现在usedCouponscartItems并且orders将包含一个item_type_idwith item_id
但是在这里,我将无法加入表格。因为它们取决于item _types

2.仅放入item_type_id每个项目:insurancesspareParts services

并且仅item_id放入usedCouponscartItems< 和orders表格。
但在这种情况下,我必须为所有服务创建父级。

itemParent
---------------------
id
name
description
item_id
item_type_id

现在再次加入在这里也很痛苦。
我将加入cartItemsto items,但有关详细信息,请在加入特定表之前再次查找它的类型。

对于这两种方法,我认为它们都不正确。如果有人可以提供帮助,可能还有其他解决方案。

标签: mysqldatabasedatabase-design

解决方案


基于这个答案,我想我可以使用下面的架构

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

但我仍然需要在这里有人的关注,如果有人可以帮助我将不胜感激。


推荐阅读