bug #13997 [2.3+][Form][DoctrineBridge] Improved loading of entities and documents (guilhermeblanco)

This PR was merged into the 2.3 branch.

Discussion
----------

[2.3+][Form][DoctrineBridge] Improved loading of entities and documents

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #13961
| License       | MIT

Commits
-------

529d99c Fixed MongoODM entity loader. Improved loading behavior of entities and documents by reusing entity loader.
This commit is contained in:
Fabien Potencier 2015-03-21 18:54:04 +01:00
commit 9f77776345
2 changed files with 7 additions and 7 deletions

View File

@ -218,10 +218,8 @@ class EntityChoiceList extends ObjectChoiceList
if (!$this->loaded) { if (!$this->loaded) {
// Optimize performance in case we have an entity loader and // Optimize performance in case we have an entity loader and
// a single-field identifier // a single-field identifier
if ($this->idAsValue) { if ($this->idAsValue && $this->entityLoader) {
$unorderedEntities = $this->entityLoader $unorderedEntities = $this->entityLoader->getEntitiesByIds($this->idField, $values);
? $this->entityLoader->getEntitiesByIds($this->idField, $values)
: $this->em->getRepository($this->class)->findBy(array($this->idField => $values));
$entitiesByValue = array(); $entitiesByValue = array();
$entities = array(); $entities = array();

View File

@ -66,9 +66,11 @@ abstract class DoctrineType extends AbstractType
$type = $this; $type = $this;
$loader = function (Options $options) use ($type) { $loader = function (Options $options) use ($type) {
if (null !== $options['query_builder']) { $queryBuilder = (null !== $options['query_builder'])
return $type->getLoader($options['em'], $options['query_builder'], $options['class']); ? $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) { $choiceList = function (Options $options) use (&$choiceListCache, $propertyAccessor) {