问题
These are requirements.
- Multiple sellers are selling product variants.
- 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
- 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