diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php index 873e4b025e..964fbdc935 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php @@ -218,10 +218,8 @@ class EntityChoiceList extends ObjectChoiceList if (!$this->loaded) { // Optimize performance in case we have an entity loader and // a single-field identifier - if ($this->idAsValue) { - $unorderedEntities = $this->entityLoader - ? $this->entityLoader->getEntitiesByIds($this->idField, $values) - : $this->em->getRepository($this->class)->findBy(array($this->idField => $values)); + if ($this->idAsValue && $this->entityLoader) { + $unorderedEntities = $this->entityLoader->getEntitiesByIds($this->idField, $values); $entitiesByValue = array(); $entities = array(); diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php index aac695c0b3..fe2d0cb44e 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php @@ -66,9 +66,11 @@ abstract class DoctrineType extends AbstractType $type = $this; $loader = function (Options $options) use ($type) { - if (null !== $options['query_builder']) { - return $type->getLoader($options['em'], $options['query_builder'], $options['class']); - } + $queryBuilder = (null !== $options['query_builder']) + ? $options['query_builder'] + : $options['em']->getRepository($options['class'])->createQueryBuilder('e'); + + return $type->getLoader($options['em'], $queryBuilder, $options['class']); }; $choiceList = function (Options $options) use (&$choiceListCache, $propertyAccessor) {