Cass
Cass

Reputation: 719

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

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

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?

Upvotes: 24

Views: 37626

Answers (3)

Mamoon Shahzad
Mamoon Shahzad

Reputation: 63

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.

Upvotes: 0

pascal
pascal

Reputation: 3365

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.

Upvotes: 0

Chris Diver
Chris Diver

Reputation: 19852

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.

Upvotes: 16

Related Questions