D
D
Demian12020-10-04 17:06:52
MySQL
Demian1, 2020-10-04 17:06:52

JSON or intermediate table?

What is the best option for storing product sizes in a database?
1. In the product table itself, in the size column, store a list of sizes in json
2. Intermediate table
product_id | 2
size_id| {'1', '2', '3'}
3. In the sizes table, where there will be several records for one product with sizes
product_id: 3 | size: 40
product_id: 3 | size: 41
etc.

I like the third option better because you can add an available column for example.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
101-s, 2020-10-04
@Demian1

if it is necessary for the client to make options and their values ​​in the admin panel, then it is usually done like this:

  1. A table is created with options that change the cost of the product. Options are size, color, etc.
  2. Next, a table is created with the option values. Here you can specify what bonuses the client will receive, how the price of the product will change when choosing an option, etc.
  3. A table where it is indicated for which product which options to display.
  4. And a table where it is indicated for which option of a particular product to display the selected options

A
Alexey Gnevyshev, 2020-10-04
@iResource

I believe that intermediate tables (as already suggested) are the best option - from the point of view that in the future, for sure, you will want to do a Product Filter by characteristics.

The third option is better

And just with option 3, it will be more difficult and costly to fit in MySQL than with option 1 and 2.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question