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 invalid ids when using queries with limit #34900
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,21 @@ public function getEntities() | |
*/ | ||
public function getEntitiesByIds($identifier, array $values) | ||
{ | ||
if (null !== $this->queryBuilder->getMaxResults() || null !== $this->queryBuilder->getFirstResult()) { | ||
// an offset or a limit would apply on results including the where clause with submitted id values | ||
// that could make invalid choices valid | ||
$choices = []; | ||
$metadata = $this->queryBuilder->getEntityManager()->getClassMetadata(current($this->queryBuilder->getRootEntities())); | ||
|
||
foreach ($this->getEntities() as $entity) { | ||
if (\in_array(current($metadata->getIdentifierValues($entity)), $values, true)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it ok with strict in_array? There is comming string variable from EntityType, but getIdentifierValues return integer from entity (if I am using strict_types). Then I get always error by comparing string vs integer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you @jirinapravnik, I've opened #35609 to fix this. |
||
$choices[] = $entity; | ||
} | ||
} | ||
|
||
return $choices; | ||
} | ||
|
||
$qb = clone $this->queryBuilder; | ||
$alias = current($qb->getRootAliases()); | ||
$parameter = 'ORMQueryBuilderLoader_getEntitiesByIds_'.$identifier; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only other way I see to fix this is to throw an exception here and to catch it in the
DoctrineChoiceLoader
to let it fall back on loading the list. But I would prefer to have it part of theEntityLoaderInterface
contract rather than leaking too much in there.