-
-
Save shofetim/1301870 to your computer and use it in GitHub Desktop.
Possible bug with CakePHP pagination?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //From a forms_controller.php | |
| if (!empty($this->passedArgs['query'])) { | |
| $this->paginate = | |
| array( | |
| 'conditions' => array( | |
| 'or' => | |
| array( | |
| 'Form.title LIKE ' => '%' . $this->passedArgs['query'] . '%', | |
| 'Tag.title LIKE ' => '%' . $this->passedArgs['query'] . '%', | |
| ) | |
| ), | |
| 'joins' => array( | |
| array( | |
| 'alias' => 'FormsTags', | |
| 'table' => 'forms_tags', | |
| 'type' => 'LEFT', | |
| 'conditions' => '`Form`.`id` = `FormsTags`.`form_id`' | |
| ), | |
| array( | |
| 'alias' => 'Tag', | |
| 'table' => 'tags', | |
| 'type' => 'LEFT', | |
| 'conditions' => '`FormsTags`.`tag_id` = `Tag`.`id`' | |
| ) | |
| ), | |
| 'group' => 'Form.id' | |
| ); | |
| } | |
| //Generated query: (passedArgs['query'] = 'titl' | |
| SELECT COUNT(*) AS `count` FROM `forms` AS `Form` LEFT JOIN forms_tags | |
| AS `FormsTags` ON (`Form`.`id` = `FormsTags`.`form_id`) LEFT JOIN tags | |
| AS `Tag` ON (`FormsTags`.`tag_id` = `Tag`.`id`) LEFT JOIN `statuses` | |
| AS `Status` ON (`Form`.`status_id` = `Status`.`id`) LEFT JOIN | |
| `form_types` AS `FormType` ON (`Form`.`form_type_id` = | |
| `FormType`.`id`) LEFT JOIN `summaries` AS `Summary` ON | |
| (`Form`.`summary_id` = `Summary`.`id`) WHERE ((`Form`.`title` LIKE | |
| '%titl%') OR (`Tag`.`title` LIKE '%titl%')) GROUP BY `Form`.`id` ; | |
| //SQL result set | |
| +-------+ | |
| | count | | |
| +-------+ | |
| | 1 | | |
| | 2 | | |
| | 2 | | |
| +-------+ | |
| 3 rows in set (0.01 sec) | |
| //What Paginator shows | |
| Showing 1 to 1 of 1 Results | |
| //But it should show | |
| Showing 1 to 3 of 3 Results | |
| It the non count part of the query does return 3 rows, which are | |
| displayed with the paginator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment