Description
Symfony version(s) affected
5.4.24
Description
The EntityType field in forms generates too many queries in the POST action.
If field is multiple and user select about 15/20 options POST method add additional queries in each options.
I know that the EntityType want to check if selected option is in our database.
But why does it work in foreach and send query through each selected options.
In ORMQueryBuilderLoader.php there is a method called getEntitiesByIds.
But when we see how it works we can see that it works in foreach of our selected options.
When we add additional inserts and selections the database queries are too large.
How to reproduce
$builder->add('test', EntityType::class, [ 'label' => 'Label test', 'class' => YourClass::class, 'multiple' => true, 'required' => false, 'choice_label' => 'name', 'choice_value' => 'id', ]);
Possible Solution
Maybe there is the chance to change this foreach to one request with all selected options with IN array.
Additional Context
No response