【发布时间】:2019-12-07 10:27:34
【问题描述】:
有些产品可以多个单位出售,基本单位是公斤。每个产品的单位有不同的重量,例如一捆产品 A 是 20 公斤,而一捆产品 B 是 30 公斤
以下是我最初的设计。
product:
id name
product_variation:
id product_id name price
product_variation_unit:
id product_variation_id unit_id
product_variation_unit_weight:
product_variation_unit_id weight
问题在于产品的大多数变化具有相同的单位和重量。所以这是我的解决方案,但我不确定这是一个好主意:
selectable_unit:
id selectable_id selectable_type unit_id
1 10 product 100
2 20 product_variation 101
selectable_unit_weight:
selectable_unit_id weight
当我想获得一个变体的单位和重量时,首先我会检查变体,如果没有,我会检查它的产品。
我有点复杂,你能帮我找到更好的解决方案或改进它吗?
【问题讨论】:
标签: mysql laravel optimization database-design polymorphic-associations