Вопрос

I'm currently thinking about how to organize my tables, and I have some information that I'm not sure were should be, one of them is the quantity of a food in a refrigerator

Database model


Is it right if I add quantity in refrigerator_has_food table? Or should this table only have foreign keys?

Это было полезно?

Решение

There is no restrictions on data stored in the pivot table. The simplest case of two IDs establishes only qualitative relations between fridges and foods: this food is stored in this fridge. If you add the counter you just turn the qualitative relation into the quantitative one: this many units of this food is stored in this fridge.

On the opposite side you have to control the counters and remove any row having counter dropped to zero to avoid silly logic yes, we store zero units of this food in this fridge.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с dba.stackexchange
scroll top