user2078736
user2078736

Reputation: 13

To-Many relationship (CoreData) with counters

I have a project with two entities - Ingredients and Dishes, with many to many relationships. In every dish I keep a relationship to the ingredients. I am trying to have a counter for the right quantity for each ingredient for every dish (for example, dish "Omlet" should have "Egg" with property "2" and "Milk" with property "1"....). I am struggling with the right way to model the counter and how to define it, any help there?

Upvotes: 0

Views: 91

Answers (1)

Flo
Flo

Reputation: 5405

You need a third entity to model this. First, remove your to-many relationship. Then create a new entity called IngredientQuantity (or whatever you like) and add a property amount of type integer. Now, add two to-one relationships to IngredientQuantity. The first one points to your Dish entity and the second one to your Ingredient entity.

Upvotes: 1

Related Questions