I have the following tables
tb_orders:
> id - PK
> name
...
> product_id - FK
tb_product:
> id - PK
> components
> color
...
In one order, I can have more than one product, but the foreign key column has only one reference to tb_product
I can use two approach for this:
- create an associative table, where would exists a row for each product ordered
tb_orders:
> id - PK
> name
...
> order - FK
tb_order_products:
> id - PK
> product_id - FK
> order_id - FK
tb_product:
> id - PK
> components
> color
...
- I can create a column products_id, in a list/array format, containing all the ordered products ids in one row: '[1, 5, 7]'. Before insert, I can check manually if the product exist in db.
I think M:M is good in the majority scenarios, but I don't see problem make this... I never see this to be honest, but seems simpler than a M:M relationship. By the way, check if the row exist in db before insert doesn't see a big problem, I don't have many products.
So, what you think about using the second approach?