Skip to content
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

[DoctrineBridge] Fixed submitting ids with query limit or offset #35609

Merged
merged 1 commit into from Feb 7, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -62,7 +62,7 @@ public function getEntitiesByIds($identifier, array $values)
$metadata = $this->queryBuilder->getEntityManager()->getClassMetadata(current($this->queryBuilder->getRootEntities()));

foreach ($this->getEntities() as $entity) {
if (\in_array(current($metadata->getIdentifierValues($entity)), $values, true)) {
if (\in_array((string) current($metadata->getIdentifierValues($entity)), $values, true)) {
HeahDude marked this conversation as resolved.
Show resolved Hide resolved
$choices[] = $entity;
}
}
Expand Down
27 changes: 26 additions & 1 deletion src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php
Expand Up @@ -956,7 +956,32 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifie
$this->assertNull($field->getData());
}

public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifierWithLimit()
public function testSingleIdentifierWithLimit()
{
$entity1 = new SingleIntIdEntity(1, 'Foo');
$entity2 = new SingleIntIdEntity(2, 'Bar');
$entity3 = new SingleIntIdEntity(3, 'Baz');

$this->persist([$entity1, $entity2, $entity3]);

$repository = $this->em->getRepository(self::SINGLE_IDENT_CLASS);

$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
'em' => 'default',
'class' => self::SINGLE_IDENT_CLASS,
'query_builder' => $repository->createQueryBuilder('e')
->where('e.id IN (1, 2, 3)')
->setMaxResults(1),
'choice_label' => 'name',
]);

$field->submit('1');

$this->assertTrue($field->isSynchronized());
$this->assertSame($entity1, $field->getData());
}

public function testDisallowChoicesThatAreNotIncludedByQueryBuilderSingleIdentifierWithLimit()
{
$entity1 = new SingleIntIdEntity(1, 'Foo');
$entity2 = new SingleIntIdEntity(2, 'Bar');
Expand Down