Skip to content

Commit

Permalink
[#3446] [Form] Fix getChoicesForValues of EntityChoiceList on empty v…
Browse files Browse the repository at this point in the history
…alues
  • Loading branch information
Thomas Chmielowiec (chmielot) committed Apr 4, 2012
1 parent 71c9dc3 commit a430f3d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Expand Up @@ -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);
}

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
}

0 comments on commit a430f3d

Please sign in to comment.