8000 merged branch chmielot/3446-empty-multiple-entity-choice (PR #3734) · symfony/symfony@d967d39 · GitHub
[go: up one dir, main page]

Skip to content

Commit d967d39

Browse files
committed
merged branch chmielot/3446-empty-multiple-entity-choice (PR #3734)
Commits ------- a430f3d [#3446] [Form] Fix getChoicesForValues of EntityChoiceList on empty values Discussion ---------- [Form] Fix reverseTransform on multiple entity form type Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: #3446, #3727 Todo: - --------------------------------------------------------------------------- by stof at 2012-04-03T23:05:55Z @bschussek ping --------------------------------------------------------------------------- by stof at 2012-04-03T23:06:45Z This is an alternate implementation for #3727 --------------------------------------------------------------------------- by chmielot at 2012-04-04T13:47:27Z OK, this is another possibility to fix this issue with working tests. What do you think about this? --------------------------------------------------------------------------- by chmielot at 2012-04-04T13:51:27Z OK, just done. --------------------------------------------------------------------------- by stof at 2012-04-04T13:51:39Z @beberlei @bschussek ping --------------------------------------------------------------------------- by bschussek at 2012-04-06T18:50:37Z @fabpot 👍
2 parents 526fb7b + a430f3d commit d967d39

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