8000 Optimize EntityType by only loading choices for values in the same wa… · symfony/symfony@a108445 · GitHub
[go: up one dir, main page]

Skip to content

Commit a108445

Browse files
guilhermeblancofabpot
authored andcommitted
Optimize EntityType by only loading choices for values in the same way that EntityLoader customization does (if you provide a query_builder).
1 parent 7b9bc80 commit a108445

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,10 @@ public function getChoicesForValues(array $values)
218218
if (!$this->loaded) {
219219
// Optimize performance in case we have an entity loader and
220220
// a single-field identifier
221-
if ($this->idAsValue && $this->entityLoader) {
222-
$unorderedEntities = $this->entityLoader->getEntitiesByIds($this->idField, $values);
221+
if ($this->idAsValue) {
222+
$unorderedEntities = $this->entityLoader
223+
? $this->entityLoader->getEntitiesByIds($this->idField, $values)
224+
: $this->em->getRepository($this->class)->findBy(array($this->idField => $values));
223225
$entitiesByValue = array();
224226
$entities = array();
225227

0 commit comments

Comments
 (0)
0