Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9bb1940

Browse filesBrowse files
committed
[DoctrineBridge] Fixed submitting ids with query limit or offset
1 parent adacae6 commit 9bb1940
Copy full SHA for 9bb1940

File tree

Expand file treeCollapse file tree

2 files changed

+27
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php
+26-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.