0

I'm building products database where a product may have multiple variants such as Size, Color, Shape, etc. for a single product. Tricky part I have trouble with is structure of the database allowing me to link the dependencies e.g. "Red" "M" "T-shirt" or "Blue" "XS" "Trousers" which in this case are variants color and size together. I want those variants to be generic so, I'm avoiding sizes, shapes, colors tables etc. Some items may not even have any variant at all or have just one e.g. just the color.

Ideally the shape would look like so

products

id name
1 T-shirt
2 Trousers

variants

id name
1 Color
2 Size

variant_values

id variant_id name
1 1 Blue
2 1 Red
3 2 XS
4 2 S
5 2 M

product_variants

I probably don’t even need variant_id here if I provide variant_value_id which already has relationship with a specific variant.

id product_id variant_id variant_value_id
1 1 1 1

The product_variants structure allows me to have "Blue T-shirt" record but how do I have those variant_value_ids work together so I could store a Blue M T-shirt or Red XS Trousers etc?

Here's my best attempt enter image description here

I have inspired my model from those threads...

...but could not find an answer that would apply to my case where I could combine the variants together.

LazioTibijczyk
  • 1,701
  • 21
  • 48
  • [How can you represent inheritance in a database?](https://stackoverflow.com/q/3579079/3404097) [More](https://stackoverflow.com/q/190296/3404097) [How to design a product table for many kinds of product where each product has many parameters](https://stackoverflow.com/q/695752/3404097) [More](https://stackoverflow.com/a/2945124/3404097) [And more](https://stackoverflow.com/q/5106335/3404097) [Re EAV](https://stackoverflow.com/a/23950836/3404097) etc etc etc [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/3404097) [ask] [Help] – philipxy Jan 18 '23 at 10:50
  • What is your 1 specific researched non-duplicate question? PS [Why should I not upload images of code/data/errors when asking a question?](https://meta.stackoverflow.com/q/285551/3404097) An ERD is an image of DDL. Use images only for what cannot be expressed as text or to augment text. Include a legend/key & explanation with an image. Paraphrase or quote from other text with credit. Give just what you need & relate it to your problem. Please don't expect us to read entire pages or try to figure out what parts you think are relevant. Just saying you searched is not showing research effort. – philipxy Jan 18 '23 at 10:59
  • Please clarify ia edits, not comments. The site is useful to you because of its standards. I just gave you a spectrum of many DB subtyping idiom Q&A regarding your question/issue. Duplicate questions are subject to closure as already answered. There's no clear phrasing of a question here. What are you trying to express by "work together" & why can't you "store a Blue M T-shirt or Red XS Trousers" & "combine the variants together"? When your question is clear the options will be a faq. Do you think this is a new question? (Rhetorical.) There is never a reason to be rude. – philipxy Jan 18 '23 at 14:03
  • I stated that I have an issue linking the two or more variants referring to the same product. Current structure I was able to research and implement does not allow more than a single variant, I was having difficulty finding the approach allowing more variant types on a single product. I was looking for the right keywords to find out more but could not without asking the question. I did edit the post leaving a single question. – LazioTibijczyk Jan 18 '23 at 16:03

0 Answers0