Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove parameters from query builder?

I have a problem with my query builder. I am using symfony. What i want to acomplish: I have a given query builder, and i want to count all rows based on this query. So i worked on following solution:

$aliases = $queryBuilder->getRootAliases();
$alias = array_values($aliases)[0];

$cloneQueryBuilder = clone $queryBuilder;
$from = $cloneQueryBuilder->getDQLPart('from');

$cloneQueryBuilder->resetDQLParts();

$newQueryBuilder = $cloneQueryBuilder
    ->select('count(' . $alias . '.id)')
    ->add('from', $from[0]);

$this->total = $newQueryBuilder->getQuery()->getSingleScalarResult();

However im getting an exception : Too many parameters: the query defines 0 parameters and you bound 1 Does anyone knows how to solve it ?

like image 277
vardius Avatar asked Mar 14 '23 15:03

vardius


1 Answers

Calling setParameters should overwrite all existing parameters.

like image 162
Joshua Avatar answered Mar 23 '23 18:03

Joshua