Reputation: 193
Hey I got the following Problem:
Foods (is a Food (egg, milk, etc) OR a Recipe (bread, which is made out of eggs, flour, etc) ).
PK: foodId
FK: recipeId
Recipe (contains 1..many foods) Bread - eggs, flour, etc..
PK: recipeId
String: name
String: cooking
FK: foodId, foodId2, foodId3, ...
Meal (many foods = a meal) bread + marmelade + coffee
PK: mealId
String: name
FK: foodId, foodId2, foodId,3, ...
How can I create something like this in a database?
I cant create more than 1 Entry with the same PK.
So example:
Recipe:
recipeId: 1
name: bread
cooking: mix all ingredients and then bake.
foodId: 1 (milk)
recipeId: 1
name: bread
cooking: mix all ingredients and then bake.
foodId: 2 (flour)
This is not possible due to the duplicate PK in recipeId.
I hope you understand my question and can provide an answer.
Upvotes: 0
Views: 74
Reputation: 13765
You could do something more like:
Recipe
----
RecipeId
Name
PrepTime
CookTime
CuisineType
RecipeSteps
----
StepId
RecipeId
Instructions
RecipeStepIngredients
----
Id
StepId
FoodId
Note, this is far from perfect, but could at least get you started.
Basically:
A meal can have many recipes
A recipe can have many steps
A single step can have many ingredients (be made up of several food items)
Upvotes: 1