Database modeling, stock and product variant

孤街醉人 提交于 2019-12-25 09:37:06

问题


These are requirements.

  1. Multiple sellers are selling product variants.
  2. Multiple sellers can sell single product variant at the same time. (This requirement can be relaxed if it makes db modeling much simpler.)

The following modeling satisfies the above two requirements.

ProductVariant
* id

Stock
* id
* product_variant
* seller
* quantity
* prices

There's another requirement

  1. Multiple variants might need to share quantity among them.

For instance, a teacher(seller) list his/her product as the following.

A class: $5.00 at 2pm .
B class: $10.00 at 2pm .

The seller is selling A and B classes but he can only receive a certain number of students for the two classes combined. i.e. stock quantity is shared.

To implement the shared quantity, I introduced ProductVariant-Stock relation

ProductVariant
* id


ProductvariantStock
* id
* product_variant
* stock

Stock
* id
* seller
* quantity

Now the question is, where should I put the price?

The first place I can think of is at the ProductvariantStock

ProductvariantStock
* id
* product_variant
* stock
* price # here

Another place I can think of is at the Stock

Stock
* id
* seller
* quantity
* price_dict_for_product_variants (as json field)

It has the benefit of ability to look up prices with stock table only. And I think I'm accustomed to think 'stock has quantity and price info', and this fits that mental model more closely.

Yet another way is to create a SellerPrice table just for price.

SellerPrice
* id
* product_variant
* seller
* price

What are the questions I should ask myself to pick a model?

来源:https://stackoverflow.com/questions/44339051/database-modeling-stock-and-product-variant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!