D
D
Dasha2016-01-12 23:21:48
MySQL
Dasha, 2016-01-12 23:21:48

What is the best way to organize the database schema?

Hello!
The situation is this:
There are goods, there are shops. Different stores may have the same product, but the price will be different.
What is the best way to organize the base in this case?
It comes to my mind to make a separate table where the product - store relationship and the column with prices for each specific relationship will be stored, but is this correct?
Application in php, laravel 5.1, MySQL database
Sorry if the question is stupid, but I want to hear advice and do everything right.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
Konstantin, 2016-01-13
@bizzi

I organized it through many-to-many relationships. You will need table pivots. How to optimize a select query in Laravel5 (many-to-many) ? I asked a question. There is little description. I saw somewhere more about pivot tables, but I can't find it.

S
Stanislav Makarov, 2016-01-12
@Nipheris

I didn’t understand the question halfway, your terminology is hard.
My suggestion:
- table Shop(id, ...);
- table Goods(id, ...);
- table ProductPrice(shop_id, product_id, price);

E
Eugene, 2016-01-12
@Nc_Soft

Add the price
product_id / shop_id / price to the link table

T
Timofey, 2016-01-14
@mr_T

How else can it actually be done? Everything is correct in the question. You can only add a scope for convenience, which adds a column with prices to the request, so that all this looks more transparent.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question