8000 [#3446] [Form] Fix getChoicesForValues of EntityChoiceList on empty v… · symfony/symfony@a430f3d · GitHub
[go: up one dir, main page]

Skip to content

Commit a430f3d

Browse files
author
Thomas Chmielowiec (chmielot)
committed
[#3446] [Form] Fix getChoicesForValues of EntityChoiceList on empty values
1 parent 71c9dc3 commit a430f3d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ public function getChoicesForValues(array $values)
175175
// Optimize performance in case we have an entity loader and
176176
// a single-field identifier
177177
if (count($this->identifier) === 1 && $this->entityLoader) {
178+
if (empty($values)) {
179+
return array();
180+
}
178181
return $this->entityLoader->getEntitiesByIds(current($this->identifier), $values);
179182
}
180183

src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/EntityChoiceListTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
1313

14+
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
1415
use Symfony\Bridge\Doctrine\Tests\DoctrineOrmTestCase;
1516
use Symfony\Bridge\Doctrine\Tests\Fixtures\ItemGroupEntity;
1617
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity;
@@ -250,4 +251,19 @@ public function testPossibleToProvideShorthandEntityName()
250251
$this->assertEquals(array(1, 2), $choiceList->getValuesForChoices(array($item1, $item2)));
251252
$this->assertEquals(array(1, 2), $choiceList->getIndicesForChoices(array($item1, $item2)));
252253
}
254+
255+
// Ticket #3446
256+
public function testGetEmptyArrayChoicesForEmptyValues()
257+
{
258+
$qb = $this->em->createQueryBuilder()->select('s')->from(self::SINGLE_IDENT_CLASS, 's');
259+
$entityLoader = new ORMQueryBuilderLoader($qb);
260+
$choiceList = new EntityChoiceList(
261+
$this->em,
262+
self::SINGLE_IDENT_CLASS,
263+
null,
264+
$entityLoader
265+
);
266+
267+
$this->assertEquals(array(), $choiceList->getChoicesForValues(array()));
268+
}
253269
}

0 commit comments

Comments
 (0)
0