-
-
Notifications
You must be signed in to change notification settings - Fork 932
Description
After updating the api-platform/core from version 2.0.3 to 2.0.4 I get the "tooManyParameters" QueryException (Too many parameters: the query defines 1 parameters and you bound 2)
I have an custom collection data provider with the following code:
public function getCollection(string $resourceClass, string $operationName = null)
{
....
$alias = 'o';
$queryBuilder = $repository->createQueryBuilder($alias);
$queryNameGenerator = new QueryNameGenerator();
$this->applyVerifiedFilter($alias, $queryBuilder, $queryNameGenerator);
foreach ($this->collectionExtensions as $extension) {
$extension->applyToCollection($queryBuilder, $queryNameGenerator, $resourceClass, $operationName);
if ($extension instanceof QueryResultCollectionExtensionInterface
&& $extension->supportsResult($resourceClass, $operationName)
) {
return $extension->getResult($queryBuilder);
}
}
return $queryBuilder->getQuery()->getResult();
}
private function applyVerifiedFilter(string $alias, QueryBuilder $queryBuilder, QueryNameGenerator $queryNameGenerator)
{
$field = 'verified';
$valueParameter = $queryNameGenerator->generateParameterName($field);
$queryBuilder
->andWhere(sprintf('%s.%s = :%s', $alias, $field, $valueParameter))
->setParameter($valueParameter, true)
;
}
For the collection I've defined some additional filters that can be applied as parameters:
generic.search_filter:
parent: 'api_platform.doctrine.orm.search_filter'
arguments: [ { id: 'exact' } ]
tags: [ { name: 'api_platform.filter', id: 'generic.search' } ]
After the api-platform update the Doctrine Query now got a mismatch when checking if ($paramCount > $mappingCount) {
When checking the DQL now only the id filter is applied and not the verified filter.
api-platform 2.0.3:
WHERE o.verified = :verified_p1 AND o.id = :id_p2
api-platform 2.0.4:
WHERE o_2.id = :id_p2
I don't know why this is happening after the update. When reverting to 2.0.3 it works fine.
The code in the doctrine query class:
$paramMappings = $this->_parserResult->getParameterMappings();
$paramCount = count($this->parameters);
$mappingCount = count($paramMappings);
In both versions (2.0.3 and 2.0.4) $this->parameters has two elements but $paramMappings has only one item in 2.0.4 but two items in 2.0.3
Does anyone know why this is happening and how to solve this issue?