DEV Community

Discussion on: Designing a Relational Database for a Cookbook

Collapse
 
dgilanda profile image
dgilanda

Hi Alex, excellent article! One element you might be able to help me with... what would the relationship look like when you have multiple recipes that feed into a menu item? That is, the recipe for Mash Potato (with ingredients of Potato and Butter) is used in multiple menu items - eg Steak and Mash (where 80grams of Mash is used), and Sausages & Mash (where 100grams of mash is used)... in each case the Qty of Mash Potato is different. Your assistance would be greatly appreciated. David

Collapse
 
pavan8085 profile image
Pavan Manjunath

Since you want a variable quantity of a recipe, you need to first make a presumption that every recipe sums to some quantity like 100 gm. Then while querying for recipes with a different quantity, you scale the ingredients accordingly. For instance, if 2.5 cups of Yeast yields 100 gms of Pizza, 80 gms of Pizza needs 2 cups of Yeast.

In order to achieve this, you can create a "Menu Table" with columns "Menu ID" and "Menu Description". You can have another "Menu Recipe Table" with columns "Menu ID", "Recipe ID" and "Scale Factor ID". Finally you create another table "Scale Factor Table" that maps IDs to scale factors like 0.8(80 gms), 1.2(120 gms), 100(10 Kgs) etc

Now, to answer a query that asks "What ingredients(along with their quantities) are required to make Steak and Mash?", you go into the "Menu Table" and get the ID of the "Steak and Mash" menu item. You use this ID and index into(join) "Menu Recipe Table" and get the Recipe ID of "Mash". Then you index into "Recipe Table" to get all ingredients of Mash. Once you get the ingredient quantities, you scale them based on the scale factor found in the "Menu Recipe Table".

Hope you get the idea.