Skip to content
Advertisement

How do i continue this database? (linking characteristics with predefined values to categories)

I’m struggling to understand how i need to do this. So my problem: I’m supposed to allow someone to sell a product on a website. Before selling, he has to chose a certain category. Each category has different characteristics that could be marked, and those characteristics are entirely dependent on the chosen category. The values of those characteristics are predefined, and are already put in the database.

My question now is how do i go on about this? How do i link those characteristics to the chosen category, and how do i link the different amounts of predefined values to those specific characteristics?

example:


category: keyboard
characteristics: condition (dropdown), keyboard layout(dropdown), extra options(multiple choice)
condition has 3 options: new, as good as new, used
keyboard layout has 2 options: qwerty, azerty
extra options is multiple choice, has 3 options: gaming keyboard, wireless, 60%


second example:


category: laptop
characteristics: condition (dropdown), refresh rate(dropdown)
condition has 3 options: new, as good as new, used
refresh rate has 5 options: 50hz, 60hz, 120hz, 144hz, 240hz


Now i would have to make this work in my database, but i can’t even figure it out on a relational database diagram.

Any form of help would certainly be appreciated!

Advertisement

Answer

I would distribute fields like this:

CATEGORIES (keyboard, laptop)
id
name

ATTRIBUTES (refresh_rate, layout)
id
name

FEATURES (50hz, 60hz, qwerty, etc)
id
attribute_id
name

CATEGORIES_ATTRIBUTES
id
category_id
attribute_id

PRODUCTS
id
name
category_id
condition (could be an enum, I put it here as every product has a condition)

PRODUCT_FEATURES
product_id
attribute_id (redundant but it can save you a join when making queries)
feature_id

Cheers!

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement