Reputation: 3548
I am developing a generic e-commerce solution using a relational database (MySQL), and I want to manage products like this:
So far so good, my current approach counts on 4 tables:
With this data model, I can combine products and attributes well, for example:
wood
which have 2 attributes (thickness
and height
) which in turn have 3 mm
and 5 mm
options for thickness and blue
and red
options for color...The problem comes with price calculation because if I declare price in attribute_product pivot table, I still do not know which value is selected for that specific attribute and product.
How could I modify the data model to be able to somehow 'link' products with attribute values? Thanks in advance.
Upvotes: 1
Views: 1918
Reputation: 776
Right, a linking table like attribute_product only link 1 instance to 1 instance, and your products can have multiple attributes, so that model doesn't work.
What you are calling the attribute_product is what most people would say is the product. It is the thing that has a price. So I would just call that "products". What you are calling products are perhaps product_categories.
So the attribute tables would be child tables to it.
Upvotes: 1