Merge pull request #1398 from dereuromark/master-paginator

PaginatorComponent should use model->order if there are no other order conditions.

Fixes #3902
This commit is contained in:
Mark Story 2013-07-04 09:21:40 -07:00
commit 76070871eb
2 changed files with 28 additions and 1 deletions

View file

@ -396,7 +396,9 @@ class PaginatorComponent extends Component {
}
$options['order'] = $order;
}
if (empty($options['order']) && !empty($object->order)) {
$options['order'] = $object->order;
}
return $options;
}

View file

@ -577,6 +577,31 @@ class PaginatorComponentTest extends CakeTestCase {
$this->assertEquals(array(3, 2, 1), $results);
}
/**
* test paginate() and model default order
*
* @return void
*/
public function testPaginateOrderModelDefault() {
$Controller = new PaginatorTestController($this->request);
$Controller->uses = array('PaginatorControllerPost');
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->PaginatorControllerPost->order = array(
$Controller->PaginatorControllerPost->alias . '.created' => 'desc'
);
$Controller->Paginator->settings = array(
'fields' => array('id', 'title', 'created'),
'maxLimit' => 10,
'paramType' => 'named'
);
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
$expected = array('2007-03-18 10:43:23', '2007-03-18 10:41:23', '2007-03-18 10:39:23');
$this->assertEquals($expected, Hash::extract($result, '{n}.PaginatorControllerPost.created'));
$this->assertEquals($Controller->PaginatorControllerPost->order, $this->Controller->request['paging']['PaginatorControllerPost']['order']);
}
/**
* test paginate() and virtualField interactions
*