Pergunta

I got 3 tables: Recipe R, Ingredient I and IngredientAmount IA

R and I got a many-to-many relation connection table.

Now, i need to chain IA to I, so that i know that fx a recipe needs potato (I) and the amount is 2 kg (IA)

Should i make a FK to I from IA or would it be okay to hook the IA FK into the many-to-many relation table between I and R?

Or is there a better way to do this?

Thanks in advance

Foi útil?

Solução

I think it gets much easier if you do it the other way around

I would read it as this:

A recipe has a set of ingredient amounts
an ingredient amount has one ingredient

So that would mean you have a recipe table like

RecipeId Title

And an ingredient amount table that references a recipe as well as an ingredient via foreign keys for example

IngredientAmountId RecipeId IngredientId Amount

And the ingredient amounts finally reference the ingredient itself

IngredientId Title

So only a few one to many relationships (one recipe has many ingredient amounts, one ingredient can belong to many ingredient amounts) needed no many to many relationship imho.

TL;DR

In your question you stated that you already "connected" recipes with ingredients, in my opinion this is flawed; there should really be a connection between recipe and ingredientamounts and another connection between ingredientamounts and ingredients.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top