Ticket #1170 (closed defect: wontfix)
Pager count query doesn't trigger dql callbacks
| Reported by: | francois | Owned by: | guilhermeblanco |
|---|---|---|---|
| Priority: | major | Milestone: | 0.11.0 |
| Component: | Pager | Version: | 0.11.0 |
| Severity: | Keywords: | ||
| Cc: | Has Test: | no | |
| Status: | Pending Core Response | Has Patch: | no |
Description
Take a table (or a template) which initializes dql callbacks in the setTableDefinition() method. This is the case of Doctrine_Template_SoftDelete for instance.
/**
* Set table definition for SoftDelete behavior
*
* @return void
*/
public function setTableDefinition()
{
$this->hasColumn($this->_options['name'], $this->_options['type'], $this->_options['length'], $this->_options['options']);
$this->addListener(new Doctrine_Template_Listener_SoftDelete($this->_options));
}
Now create a pager on that table, with whatever query you want. The pager will issue two database queries: one for the count, and one for the page. The problem is that the count query doesn't execute the dql callbacks (e.g. preDqlSelect()) registered on the table. This results in wrong counts on pagers on tables with DQL behaviors.
The reason seems to be that the count query doesn't execute the setTableDefinition(). If I write
Doctrine_Manager::getInstance()->setAttribute('use_dql_callbacks', true);
in a place where I'm sure it is executed before the pager, the count query problem disappears. Another workaround is to call Doctrine::getTable('MyTable'); before executing the pager (this one will execute setTableDefinition()).
Hope the problem is clear...