Answer the question
In order to leave comments, you need to log in
How to properly design a database relationship between two products?
Hello!
There is a product (linen), the product has size options (double, single).
Task #1 ( DONE !): split the product into options (create a separate product for each option with its own URL). As a result, we have two products:
- ID 10 Double bed linen
- ID 15 Single
bed linen In fact, they are different products.
Question: how can I design a table for the relationships between these products. To have each of these products refer to each other?
I see it like this:
linking_options (table)
product_id | linking_product_id
--------------------------------------
10 | 15
15 | 10
In this case, we link two goods. But, if you need to link 3 or 4 products together? Then add additional columns (stupid as for me)....
Tell me, please, how best to implement the table.
Answer the question
In order to leave comments, you need to log in
Question: how can I design a table for the relationships between these products. To have each of these products refer to each other?
CREATE TABLE groups_of_goods (
group_id BIGINT UNSIGNED NOT NULL,
product_id BIGINT UNSIGNED NOT NULL,
PRIMARY KEY (group_id, product_id),
FOREIGN KEY fk_product (product_id) REFERENCES product (product_id)
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question