CakeDC/tags — Issue #21: Pagination Count in 2.0
Author: asecondwill
Created: 2011-12-19 04:30:27+00:00
State: open

I'm not getting a correct count for pagination using the 2 branch in a 2.0 project

if (isset($this->passedArgs['tag'])) {
$this->paginate['Tagged'] = array(
'limit' => 3,
'model' => 'Post',
'tagged',
'by' => $this->passedArgs['tag']);
$posts = $this->paginate('Tagged');
} else {
$this->Post->recursive = 1;
$posts = $this->paginate();
}

I'm setting up the tags in the usual, minimal way, actsas 'Tags.Taggable'

These are the sql queries generated:

SELECT DISTINCT `Post`.`id`,`Post`.`title`,`Post`.`body`,`Post`.`excerpt`,`Post`.`published`,`Post`.`created`,`Post`.`modified`,`Post`.`hero`,`Post`.`document` FROM `tagged` AS `Tagged` LEFT JOIN `tags` AS `Tag` ON (`Tagged`.`tag_id` = `Tag`.`id`) INNER JOIN `posts` AS `Post` ON (`Tagged`.`foreign_key` = `Post`.`id` AND `Tagged`.`model` = 'Post') WHERE `Tag`.`keyname` = 'cakephp' LIMIT 3,

SELECT COUNT(*) AS `count` FROM `tagged` AS `Tagged` LEFT JOIN `tags` AS `Tag` ON (`Tagged`.`tag_id` = `Tag`.`id`) INNER JOIN `posts` AS `Post` ON (`Tagged`.`foreign_key` = `Post`.`id` AND `Tagged`.`model` = 'Post') WHERE 1 = 1

So obiously the paginator thinks there are far more pages than there really is.

Placing debug statements in the tagged.php model in the plugin, $query['operation'] is never set, so the count statements there (before and after) are never used.