简体   繁体   中英

multiple attribute database design

I have a product that has many color variants and I need some help to design the database tables. It's the same product but not all models have the same color variants. One product has 3 color and other may have 6 colors.

Here is something to get you going. You can have price field in both, models and options then sum it in your script, that way you can have different price depending on model and color option.

在此处输入图片说明

UPDATE

Your query will be somoething like:

SELECT
p.name AS 'product',
m.name AS 'model',
m.description AS 'model_description',
o.name AS 'option'
FROM `products` AS p

LEFT JOIN `models` AS m
ON (p.ID = m.product_id)

LEFT JOIN `option_to_model` AS otm
ON (m.ID = otm.model_id)

LEFT JOIN `options` AS o
ON (otm.option_id = o.ID)

Here is a live example for you SQLFiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM