Context : I'm getting many difficulties to manage a ManyToMany relation between entities A and B. I got a form for A entity with some input fields for A and a CollectionType to add form for B entity. The B form only get one field: it's a select input to choose a B1 object based on its name property. I don't get any trouble displaying an A form with 5 (for example) included B objects in select input in the Edit view of A object.
My problem is: for example in the Edit view of an object A1, when I change some B select forms values from B1 to B2 or any other value, then submit the A1 form for Editing is good and the A1 object seems good too. But then, when I go to a different A object (A2 for instance) with others B objects combined (whose was included a B1 object especially), then I see a B2 object instead of a B1. And then, after checking in the database, I realized that I've finally change the name property of B object from B1 to B2, and now there are two B objects with the same name.
What I have already tried :
- to test with a ChoiceType or EntityType in B form
- to test with 'by_reference' => false in A form and/or B form
- to settle 'choice_label' or 'choice_value' in B form
- to initialize ManyToMany relation with mappingBy/inversedBy both possiblity on entities A and B
- to set a 'query_builder' and/or 'choices'
- ...
- and of course to search on internet during during a long time
I will appreciated a lot any help ! Thx