Skip to content

Commit 1a16b64

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: Updated all the README files [TwigBundle] Fix failing test on appveyor Improved the error message when using "@" in a decorated service Improve error reporting in router panel of web profiler [DoctrineBridge][Form] Fix performance regression in EntityType [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths Allow to normalize \Traversable minor [Form] fix tests added by #16886 Remove _path from query parameters when fragment is a subrequest and request attributes are already set Added tests for _path removal in FragmentListener Simplified everything Added a test Fixed the problem in an easier way Fixed a syntax issue Improved the error message when a template is not found [CodingStandards] Conformed to coding standards [TwigBundle] fixed Include file locations in "Template could not be found" exception
2 parents 55e0e2e + 3dfe69f commit 1a16b64

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

Form/ChoiceList/DoctrineChoiceLoader.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ public function loadChoicesForValues(array $values, $value = null)
146146

147147
// Optimize performance in case we have an object loader and
148148
// a single-field identifier
149-
if (null === $value && !$this->choiceList && $this->objectLoader && $this->idReader->isSingleId()) {
149+
$optimize = null === $value || is_array($value) && $value[0] === $this->idReader;
150+
151+
if ($optimize && !$this->choiceList && $this->objectLoader && $this->idReader->isSingleId()) {
150152
$unorderedObjects = $this->objectLoader->getEntitiesByIds($this->idReader->getIdField(), $values);
151153
$objectsById = array();
152154
$objects = array();

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ various Symfony components.
77
Resources
88
---------
99

10-
You can run the unit tests with the following command:
11-
12-
$ cd path/to/Symfony/Bridge/Doctrine/
13-
$ composer install
14-
$ phpunit
10+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
11+
* [Report issues](https://github.com/symfony/symfony/issues) and
12+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
13+
in the [main Symfony repository](https://github.com/symfony/symfony)

Tests/Form/Type/EntityTypeTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,30 @@ public function testOverrideChoicesValuesWithCallable()
802802
$this->assertSame('BooGroup/Bar', $field->getViewData());
803803
}
804804

805+
public function testChoicesForValuesOptimization()
806+
{
807+
$entity1 = new SingleIntIdEntity(1, 'Foo');
808+
$entity2 = new SingleIntIdEntity(2, 'Bar');
809+
810+
$this->persist(array($entity1, $entity2));
811+
812+
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
813+
'em' => 'default',
814+
'class' => self::SINGLE_IDENT_CLASS,
815+
'choice_label' => 'name',
816+
));
817+
818+
$this->em->clear();
819+
820+
$field->submit(1);
821+
822+
$unitOfWorkIdentityMap = $this->em->getUnitOfWork()->getIdentityMap();
823+
$managedEntitiesNames = array_map('strval', $unitOfWorkIdentityMap['Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity']);
824+
825+
$this->assertContains((string) $entity1, $managedEntitiesNames);
826+
$this->assertNotContains((string) $entity2, $managedEntitiesNames);
827+
}
828+
805829
public function testGroupByChoices()
806830
{
807831
$item1 = new GroupableEntity(1, 'Foo', 'Group1');

0 commit comments

Comments
 (0)