-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] EntityType in forms generates too many queries #50898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We will need a reproducer for that. I strongly doubt that your suggestion of the cause is right. |
again, please provide a reproducer. |
Hi, Symfony ver 5.4 |
What does one have to in that application to reproduce what you experience? |
Put debug mark in getEntitiesByIds method, next just add task in /tasks/new getEntitiesByIds method get value by each and in last call this method get all values |
#50937 fixed this isssue, thanks |
This PR was merged into the 5.4 branch. Discussion ---------- [Form] fetch all known ChoiceType values at once | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #50898 | License | MIT | Doc PR | Commits ------- 5e0f832 fetch all known ChoiceType values at once
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
The text was updated successfully, but these errors were encountered: