[DC-914] Doctrine_Pager ignores custom COUNT query Created: 02/Nov/10 Updated: 07/Nov/11
|Reporter:||Arnoldas Lukasevicius||Assignee:||Guilherme Blanco|
Zend Server CE
I found some problem when I tried to define custom query for results counting. Defined custom COUNT query is totally ignored and executed default one. I will give you full description of problem bellow.
We have following source code:
Let's check custom query before calling $pager->execute() method:
Looks like until now is everything is correct. Let's call $pager->execute() method:
Let's check executed queries using Symfony SQL queries log panel:
Executed COUNT query is not same we set using $pager->setCountQuery($q_count). Our defined custom COUNT query is totally ignored and executed default one:
INSTEAD OF THIS CUSTOM COUNT QUERY:
EXECUTED DEFAULT COUNT QUERY:
|Comment by Alex Cardoso [ 07/Nov/11 ]|
I found a possible solution to the problem.
That occurs not because the Pager countQuery but in a method used inside the Query class.
When you set the Query or CountQuery for Pager and execute it, it calls a Query method called count(). This method by yourself call another Query class method named Query::getCountSqlQuery().
This method rather than simply execute the query that you passed earlier, simply create a new query.
Below is a possible solution to the problem:
Query.php (Doctrine Stable 1.2.4)