Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[#3446] [Form] Fix getChoicesForValues of EntityChoiceList on empty v…

…alues
  • Loading branch information...
commit a430f3d8a6caffde3a6439cf0c5778abb1508413 1 parent 71c9dc3
Thomas Chmielowiec (chmielot) authored
View
3  src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php
@@ -175,6 +175,9 @@ public function getChoicesForValues(array $values)
// Optimize performance in case we have an entity loader and
// a single-field identifier
if (count($this->identifier) === 1 && $this->entityLoader) {
+ if (empty($values)) {
+ return array();
+ }
return $this->entityLoader->getEntitiesByIds(current($this->identifier), $values);
}
View
16 src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/EntityChoiceListTest.php
@@ -11,6 +11,7 @@
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
+use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
use Symfony\Bridge\Doctrine\Tests\DoctrineOrmTestCase;
use Symfony\Bridge\Doctrine\Tests\Fixtures\ItemGroupEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity;
@@ -250,4 +251,19 @@ public function testPossibleToProvideShorthandEntityName()
$this->assertEquals(array(1, 2), $choiceList->getValuesForChoices(array($item1, $item2)));
$this->assertEquals(array(1, 2), $choiceList->getIndicesForChoices(array($item1, $item2)));
}
+
+ // Ticket #3446
+ public function testGetEmptyArrayChoicesForEmptyValues()
+ {
+ $qb = $this->em->createQueryBuilder()->select('s')->from(self::SINGLE_IDENT_CLASS, 's');
+ $entityLoader = new ORMQueryBuilderLoader($qb);
+ $choiceList = new EntityChoiceList(
+ $this->em,
+ self::SINGLE_IDENT_CLASS,
+ null,
+ $entityLoader
+ );
+
+ $this->assertEquals(array(), $choiceList->getChoicesForValues(array()));
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.