8000 [Form] Fix reverseTransform on multiple entity form type by chmielot · Pull Request #3734 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Fix reverseTransform on multiple entity form type #3734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[#3446] [Form] Fix getChoicesForValues of EntityChoiceList on empty v…
…alues
  • Loading branch information
Thomas Chmielowiec (chmielot) committed Apr 4, 2012
commit a430f3d8a6caffde3a6439cf0c5778abb1508413
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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