DB storing food recipes: How to associate the two tables? Would I need a third table?
Asked Answered
P

3

24

I want to make a database of recipes with at least two tables:

  • Recipe (description, ingredients, directions, ...)
  • Ingredients (ingredient type, other attributes, ...)

What would be a way to associate the two tables?

Would I need a third table that would store the several relationships from a recipe to multiple ingredients?

Progression answered 12/7, 2010 at 2:37 Comment(1)
Does this answer your question? many-to-many relationship in database designLibya
C
16

Does one recipe have many ingredients or many recipe's have many ingredients

I'd expect it will be the latter to allow you to find recipe's by ingredient.

So you will need an intermediate table to break the many to many relationship into two one to many relationships.

Recipe(RecipeID, etc...) 
Ingredients(IngredientID, etc....)
RecipeIngredients(RecipeID, IngredientID, etc..)

Then in RecipeIngredients I would put information such as quantities of that ingredient for that recipe.

Chill answered 12/7, 2010 at 2:40 Comment(0)
T
0

You could consider something like a folder of text files, with a full-text index of some sort.

Or a table like Recipes(ID, LikeRatio, Description as text). Again with a full-text search.

Theorically you could use a normalized model like the one @Mike suggested. But looking at actual recipes, it needs to be more flexible. For example in this model, there's no evidence of the use at some step of the outcome of a previous step.

Troublous answered 12/7, 2010 at 3:53 Comment(1)
Hmm this looks like putting work into writing a database rather than simply using an existing database. The work then becomes creation of the data model.Fleischman
A
0

You can use Firebase for that and don't need tables just create documents and have access to those documents index wise. You are creating food recipe app which will store the food item image, name, ingredients and cooking method by name of itemDescription. Store those data items in a Firebase database and make a collection of different categories under which come food items of the relevant category.

Under each collection there will be an auto ID document and under that document there will each field data specified. like in each and every document for every food item it will store the itemImage, itemDescription, itemName and itemIngredients.

We can access these in our UI through references and show them in the gridveiw or listview using cards.

Ama answered 29/1, 2024 at 16:43 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Holomorphic

© 2022 - 2025 — McMap. All rights reserved.