Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37b11a8

Browse files
committed
Allow setQueryBuilder() callable to return a custom QueryBuilder
The return value of the callable passed to setQueryBuilder() was ignored in AssociationConfigurator, making it impossible to replace the QueryBuilder with one that includes eager loading (leftJoin + addSelect). This caused N+1 queries when using group_by or choice_label that access related entities on each choice. Fixes EasyCorp#7434
1 parent 3aaf2ba commit 37b11a8

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/Field/Configurator/AssociationConfigurator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
203203
// it would then be identical to the one used in autocomplete action, but it is a bit complex getting it in here
204204
$queryBuilder = $repository->createQueryBuilder('entity');
205205
if (null !== $queryBuilderCallable = $field->getCustomOption(AssociationField::OPTION_QUERY_BUILDER_CALLABLE)) {
206-
$queryBuilderCallable($queryBuilder);
206+
$queryBuilder = $queryBuilderCallable($queryBuilder) ?? $queryBuilder;
207207
}
208208

209209
return $queryBuilder;

0 commit comments

Comments
 (0)