Skip to content
Advertisement

Relation ManyToMany with Symfony 5 : do not save

For my project, I created 2 entities : Recipe & Ingredient. They are a ManyToMany relation. mysql shema

I generated everything from the console (entity & CRUD). But, I can’t save ingredients for recipes, the field ‘ingredients’do not save anything, just Date and Name.

I try add a “cascade={“persist”}” in my entity, but it does not work. thank you in advance for your help !

Ingredient.php

JavaScript

IngredientController.php

JavaScript

Recette.php

JavaScript

RecetteController.php

JavaScript

RecetteType.php

JavaScript

Advertisement

Answer

In relationship ManyToMany, one-way remove/add is not working. For such manyToMany relationship, you have to call the remove/add methods from both entities $recette->addIngredient($ingredients); $Ingredients->addRecettes($recette);

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement