[#3446] [Form] Fix getChoicesForValues of EntityChoiceList on empty values
This commit is contained in:
parent
71c9dc31f4
commit
a430f3d8a6
@ -175,6 +175,9 @@ class EntityChoiceList extends ObjectChoiceList
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -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 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
||||
$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()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user