'Error : The entity passed to the choice field must be managed
In a search form, when I submit for the second time the datas containing a equipment criterion, I receive this error :
Entity of type "App\Entity\Equipment" passed to the choice field must be managed. Maybe you forget to persist it in the entity manager?
There is a example flow to reproduce the problem :
- I introduce criteria (without equipment criterion) to find the corresponding adverts
- I submit the serach form
- The adverts are showed without problem
- I introduce one or many equipment criteria (via a multiple choices list of entity type)
- I submit the serach form
- The adverts are showed without problem
- I introduce for the second time one or many new equipment criteria
- I submit the search form
- I receive the error :
Entity of type "App\Entity\Equipment" passed to the choice field must be managed. Maybe you forget to persist it in the entity manager?
Somebody have an idea to resolve this problem?
Thanks for your help.
Solution 1:[1]
In your CrudController, have you
*AssociationField::new('criterion')
->setLabel('AS_U_Want')
->setFormType(ChoiceType::class)
->setFormattedValue('name')
->setFormTypeOptions([
'by_reference' => true, // !! Important
])
->autocomplete(),*
??
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | VDevS |