Which would be the best solution to join 4 different tables with X tables that has to be the same for the 4 tables?
Let's presume we have 2 tables MENU
and PLATES
each of that tables could be joined with tables like IMAGES
, DESCRIPTIONS
, ALLERGENS
and other tables that will give some properties to MENU
and PLATES
Which would be the best practise to join those property tables with the main ones?
Should i create in each property table a column for each main table as foreign key? Like this:
+----+--------------+--------+----------+
| ID | DESC | ID_MEN | ID_PLATE |
+----+--------------+--------+----------+
| 1 | PIZZE | 1 | |
+----+--------------+--------+----------+
| 2 | CHICKEN SOUP | | 4 |
+----+--------------+--------+----------+
Or should i create a intersect table for each main table that has FK for each propriety table like this:
+--------+---------+-----------+
| ID_MEN | ID_DESC | ID_IMAGES |
+--------+---------+-----------+
| 1 | 2 | 3 |
+--------+---------+-----------+
MENU
and aPLATES
record? In my mind those seem to be the same thing but I would imagine you have a more granular definition, which is why they are 2 separate tables. Also, are the other "attributes" (IMAGES
,DESCRIPTIONS
,ALLERGENS
) a 1-to-1 relationship or is aMENU
/PLATES
object allowed to have multiple of each? (I am going to guess thatDESCRIPTIONS
may be a 1-to-1 where the others could be a 1-to-many relationship)MENU
/PLATES
could have multiple attributes so 1-to-many, the tables are separate as i'm working on a yet created database where aMENU
has almost same columns ofPLATES
but are separated as some columns are different and actually thePLATES
belong toMENU
but eachPLATE
orMENU
could have 1 or moreimages
1 or moredescription
(different language) and differentallergens
likePLATE
"pizza" could haveallergens
"pasta", "pomodoro" or aMENU
could have some generic allergensPLATES
is a child table toMENU
? Or are they just separate tables which hold similar but different elements?PLATES
are child of menu but there is another tableITEMS
that is the same ofPLAYES
which hold similar elements but doesn't belong to anyMENU
(the tableITEMS
) should have same proprieties asMENU
andPLATES
like images etc..