10000 bug #35609 [DoctrineBridge] Fixed submitting ids with query limit or … · symfony/symfony@e41a312 · GitHub
[go: up one dir, main page]

Skip to content

Commit e41a312

Browse files
committed
bug #35609 [DoctrineBridge] Fixed submitting ids with query limit or offset (HeahDude)
This PR was merged into the 3.4 branch. Discussion ---------- [DoctrineBridge] Fixed submitting ids with query limit or offset | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #34900 (comment) <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | ~ <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch master. --> Commits ------- 9bb1940 [DoctrineBridge] Fixed submitting ids with query limit or offset
2 parents 36ffca3 + 9bb1940 commit e41a312

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getEntitiesByIds($identifier, array $values)
6262
$metadata = $this->queryBuilder->getEntityManager()->getClassMetadata(current($this->queryBuilder->getRootEntities()));
6363

6464
foreach ($this->getEntities() as $entity) {
65-
if (\in_array(current($metadata->getIdentifierValues($entity)), $values, true)) {
65+
if (\in_array((string) current($metadata->getIdentifierValues($entity)), $values, true)) {
6666
$choices[] = $entity;
6767
}
6868
}

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,32 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifie
956956
$this->assertNull($field->getData());
957957
}
958958

959-
public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifierWithLimit()
959+
public function testSingleIdentifierWithLimit()
960+
{
961+
$entity1 = new SingleIntIdEntity(1, 'Foo');
962+
$entity2 = new SingleIntIdEntity(2, 'Bar');
963+
$entity3 = new SingleIntIdEntity(3, 'Baz');
964+
965+
$this->persist([$entity1, $entity2, $entity3]);
966+
967+
$repository = $this->em->getRepository(self::SINGLE_IDENT_CLASS);
968+
969+
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
970+
'em' => 'default',
971+
'class' => self::SINGLE_IDENT_CLASS,
972+
'query_builder' => $repository->createQueryBuilder('e')
973+
->where('e.id IN (1, 2, 3)')
974+
->setMaxResults(1),
975+
'choice_label' => 'name',
976+
]);
977+
978+
$field->submit('1');
979+
980+
$this->assertTrue($field->isSynchronized());
981+
$this->assertSame($entity1, $field->getData());
982+
}
983+
984+
public function testDisallowChoicesThatAreNotIncludedByQueryBuilderSingleIdentifierWithLimit()
960985
{
961986
$entity1 = new SingleIntIdEntity(1, 'Foo');
962987
$entity2 = new SingleIntIdEntity(2, 'Bar');

0 commit comments

Comments
 (0)
0