This must be really basic stuff since I did not find any discussion about it. However I have struggled with this for a while.
I have pretty basic many-to-many relation with extra field implemented like in this example (double one-to-many relation). This works nicely when creating new entities and saving them to database. I am now trying to create editing feature and came across some problems.
Lets say my main entity is called Recipe, which has many-to-many relation with Ingredient entity. Extra field(s) like "amount" are in RecipeIngredient entity. Recipe class has setRecipeIngredient method, which adds RecipeIngredient object to ingredients array.
Should I create some "clearRecipeIngredients" method to Recipe class, which would remove all RecipeIngredient objects? I would call this when editing Recipe, then creating new RecipeIngredient entities from my data and populating ingredients array like when creating new entity? I admit that my cascade settings are probably not set correctly this to work, but I try fixing it next.
Any related examples would be great.