Allowing paginate() to send any extra parameters to the find call, and updating it to use new find notation.

Updating test in Containable to reflect how to properly use pagination: just set your 'contain' setting as you do with other pagination parameters, for example:
var $paginate = array('Article' => array('conditions' => ..., 'contain' => array( ... ));
and then do your normal paginate(), without having to set reset to false nor call resetBindings(). Check the test case for an actual example.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7010 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2008-05-22 16:25:10 +00:00
parent d1d06eb4fe
commit 8f92952d46
2 changed files with 7 additions and 8 deletions

View file

@ -979,10 +979,11 @@ class Controller extends Object {
} }
$recursive = $object->recursive; $recursive = $object->recursive;
$extra = array_diff_key($defaults, compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive'));
if (method_exists($object, 'paginateCount')) { if (method_exists($object, 'paginateCount')) {
$count = $object->paginateCount($conditions, $recursive); $count = $object->paginateCount($conditions, $recursive);
} else { } else {
$count = $object->findCount($conditions, $recursive); $count = $object->find('count', array_merge(compact('conditions', 'recursive'), $extra));
} }
$pageCount = intval(ceil($count / $limit)); $pageCount = intval(ceil($count / $limit));
@ -995,7 +996,7 @@ class Controller extends Object {
if (method_exists($object, 'paginate')) { if (method_exists($object, 'paginate')) {
$results = $object->paginate($conditions, $fields, $order, $limit, $page, $recursive); $results = $object->paginate($conditions, $fields, $order, $limit, $page, $recursive);
} else { } else {
$results = $object->findAll($conditions, $fields, $order, $limit, $page, $recursive); $results = $object->find('all', array_merge(compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive'), $extra));
} }
$paging = array( $paging = array(
'page' => $page, 'page' => $page,

View file

@ -2976,14 +2976,12 @@ class ContainableTest extends CakeTestCase {
$Controller->passedArgs[] = '1'; $Controller->passedArgs[] = '1';
$Controller->params['url'] = array(); $Controller->params['url'] = array();
$Controller->constructClasses(); $Controller->constructClasses();
$Controller->paginate = array('Article' => array('fields' => array('title'))); $Controller->paginate = array('Article' => array('fields' => array('title'), 'contain' => array('User(user)')));
$Controller->Article->contain(false, array('User(user)'));
$result = $Controller->paginate('Article'); $result = $Controller->paginate('Article');
$Controller->Article->resetBindings();
$expected = array( $expected = array(
array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano')), array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry')), array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)),
array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano')), array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
); );
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);