views:

67

answers:

1

In order to better learn both Cocoa and Core Data, I decided to build an application that holds cooking recipes. However, while trying to create the CD model, I already got stuck.

These are three of the classes, simplified:

Recipe:
name
ingredients
instructions

Ingredient:
name
unit (liter, teaspoon etc)

Of course, the ingredients relation in the Recipe also needs to keep track of the amount that is needed. If I were to immediately build a SQL table, I'd end up with:

Recipe:  Ingredient:  Recipe_Ingredient:
id       id           recipe_id
name     name         ingredient_id
instr    unit         amount

Exactly how can I put this Recipe_Ingredient relation into a CD model? Will I simply have to add a RecipeIngredients entity which contains these attributes?

A: 

Yes, if you want to add attributes to the relationship you need to use an intermediate entity that joins the Recipe and Ingredients entities together as well as adds the amount attribute.

If you are new to Core Data you might also find the following two links useful:

m5h
So it is as I thought, thanks for the confirmation!
nephilim