0
votes

I have two entities with a one to many relationship:

Recipe:

  • recipeID: Int
  • recipeName: String

Ingredient:

  • ingredientID
  • ingredientName

In my app there is a table view that displays all ingredients for the recipe. How it is possible to insert new ingredients?

I would like to insert it in that way: "insert ingredientName where recipe.recipeID = 1". Is that possible? Until now I could only insert a completely new Recipe.

Please help me, thanks in advance.

1
you display and select recipes somehow? - Wain

1 Answers

0
votes
  1. Make sure it's an Inverse relationship in your Model
  2. Create an Ingredient
  3. Assign the Recipie to the Ingredient. This will autamatically add Ingredient to the Recipie since it's and inverse relationship
  4. Save your context
  5. Update your fetch results( or whatever is your dataSource of your table view )
  6. reload your tableView