Skip to content

Commit 5bdae4a

Browse files
Fixed MongoODM entity loader. Improved loading behavior of entities and documents by reusing entity loader.
1 parent f368a6e commit 5bdae4a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Form/ChoiceList/EntityChoiceList.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,8 @@ 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) {
222-
$unorderedEntities = $this->entityLoader
223-
? $this->entityLoader->getEntitiesByIds($this->idField, $values)
224-
: $this->em->getRepository($this->class)->findBy(array($this->idField => $values));
221+
if ($this->idAsValue && $this->entityLoader) {
222+
$unorderedEntities = $this->entityLoader->getEntitiesByIds($this->idField, $values);
225223
$entitiesByValue = array();
226224
$entities = array();
227225

Form/Type/DoctrineType.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
6666
$type = $this;
6767

6868
$loader = function (Options $options) use ($type) {
69-
if (null !== $options['query_builder']) {
70-
return $type->getLoader($options['em'], $options['query_builder'], $options['class']);
71-
}
69+
$queryBuilder = (null !== $options['query_builder'])
70+
? $options['query_builder']
71+
: $options['em']->getRepository($options['class'])->createQueryBuilder('e');
72+
73+
return $type->getLoader($options['em'], $queryBuilder, $options['class']);
7274
};
7375

7476
$choiceList = function (Options $options) use (&$choiceListCache, $propertyAccessor) {

0 commit comments

Comments
 (0)