From a10844587b4494c678e8e2095a05f1bb88d06cb2 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Thu, 5 Feb 2015 17:41:00 +0000 Subject: [PATCH] Optimize EntityType by only loading choices for values in the same way that EntityLoader customization does (if you provide a query_builder). --- .../Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php index 964fbdc9354a..873e4b025e0f 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php @@ -218,8 +218,10 @@ public function getChoicesForValues(array $values) if (!$this->loaded) { // Optimize performance in case we have an entity loader and // a single-field identifier - if ($this->idAsValue && $this->entityLoader) { - $unorderedEntities = $this->entityLoader->getEntitiesByIds($this->idField, $values); + if ($this->idAsValue) { + $unorderedEntities = $this->entityLoader + ? $this->entityLoader->getEntitiesByIds($this->idField, $values) + : $this->em->getRepository($this->class)->findBy(array($this->idField => $values)); $entitiesByValue = array(); $entities = array();