Skip to content
Permalink
Browse files

Allow numeric sorts in PaginatorComponent.

When paginating data, we should not ignore numerically indexed order
conditions. Instead they should be handled similar to Model::find().

This creates a slightly different behavior when model's have default
sorting applied as more default sort options forms will be honoured.

Refs #5964
  • Loading branch information...
markstory committed Feb 26, 2015
1 parent ea79cf5 commit c92cfb413fd98c0486f293f3c524e3337aba70cc
@@ -388,6 +388,10 @@ public function validateSort(Model $object, array $options, array $whitelist = a
if (!empty($options['order']) && is_array($options['order'])) {
$order = array();
foreach ($options['order'] as $key => $value) {
if (is_int($key)) {
$key = $value;
$value = 'asc';
}
$field = $key;
$alias = $object->alias;
if (strpos($key, '.') !== false) {
@@ -454,6 +454,13 @@ public function testPaginateExtraParams() {
$this->assertEquals(array(1, 2, 3), Hash::extract($result, '{n}.PaginatorControllerPost.id'));
$this->assertTrue(!isset($Controller->PaginatorControllerPost->lastQueries[1]['contain']));
$Controller->Paginator->settings = array(
'order' => array('PaginatorControllerPost.author_id')
);
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
$this->assertEquals(1, $Controller->params['paging']['PaginatorControllerPost']['page']);
$this->assertEquals(array(1, 3, 2), Hash::extract($result, '{n}.PaginatorControllerPost.id'));
$Controller->request->params['named'] = array('page' => '-1');
$Controller->Paginator->settings = array(
'PaginatorControllerPost' => array(
@@ -606,7 +613,7 @@ public function testPaginateOrderModelDefault() {
$Controller->PaginatorControllerPost->order = array('PaginatorControllerPost.id');
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
$this->assertEmpty($result['order']);
$this->assertEquals(array('PaginatorControllerPost.id' => 'asc'), $result['order']);
$Controller->PaginatorControllerPost->order = 'PaginatorControllerPost.id';
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
@@ -617,7 +624,10 @@ public function testPaginateOrderModelDefault() {
'PaginatorControllerPost.created' => 'asc'
);
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
$expected = array('PaginatorControllerPost.created' => 'asc');
$expected = array(
'PaginatorControllerPost.id' => 'asc',
'PaginatorControllerPost.created' => 'asc'
);
$this->assertEquals($expected, $result['order']);
}

0 comments on commit c92cfb4

Please sign in to comment.
You can’t perform that action at this time.