Skip to content
Permalink
Browse files

Fixing bug when trying to Paginate ordering by multiple keys.

  • Loading branch information...
renan committed Oct 12, 2011
1 parent b261024 commit 49f40354126c874ae00008a0e846edc6a47813d2
@@ -340,22 +340,23 @@ public function validateSort($object, $options, $whitelist = array()) {
}
if (!empty($options['order']) && is_array($options['order'])) {
$alias = $object->alias;
$key = $field = key($options['order']);
if (strpos($key, '.') !== false) {
list($alias, $field) = explode('.', $key);
}
$value = $options['order'][$key];
unset($options['order'][$key]);
$order = array();
foreach ($options['order'] as $key => $value) {
$field = $key;
$alias = $object->alias;
if (strpos($key, '.') !== false) {
list($alias, $field) = explode('.', $key);
}
if ($object->hasField($field)) {
$options['order'][$alias . '.' . $field] = $value;
} elseif ($object->hasField($key, true)) {
$options['order'][$field] = $value;
} elseif (isset($object->{$alias}) && $object->{$alias}->hasField($field)) {
$options['order'][$alias . '.' . $field] = $value;
if ($object->hasField($field)) {
$order[$alias . '.' . $field] = $value;
} elseif ($object->hasField($key, true)) {
$order[$field] = $value;
} elseif (isset($object->{$alias}) && $object->{$alias}->hasField($field)) {
$order[$alias . '.' . $field] = $value;
}
}
$options['order'] = $order;
}
return $options;
@@ -683,6 +683,29 @@ public function testValidateSortVirtualField() {
$this->assertEquals('desc', $result['order']['something']);
}
/**
* test that multiple sort works.
*
* @return void
*/
public function testValidateSortMultiple() {
$model = $this->getMock('Model');
$model->alias = 'model';
$model->expects($this->any())->method('hasField')->will($this->returnValue(true));
$options = array('order' => array(
'author_id' => 'asc',
'title' => 'asc'
));
$result = $this->Paginator->validateSort($model, $options);
$expected = array(
'model.author_id' => 'asc',
'model.title' => 'asc'
);
$this->assertEquals($expected, $result['order']);
}
/**
* test that maxLimit is respected
*

0 comments on commit 49f4035

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