Permalink
Browse files

Making sure the correct alias is selected for pagination sorting

  • Loading branch information...
1 parent a9b5b0c commit db39c242cc8001106bae4530434bdac5878bf438 @lorenzo lorenzo committed Apr 28, 2013
Showing with 19 additions and 1 deletion.
  1. +1 −1 cake/libs/controller/controller.php
  2. +18 −0 cake/tests/cases/libs/controller/controller.test.php
View
2 cake/libs/controller/controller.php
@@ -1020,7 +1020,7 @@ function paginate($object = null, $scope = array(), $whitelist = array()) {
if (isset($object->{$alias}) && $object->{$alias}->hasField($field)) {
$options['order'][$alias . '.' . $field] = $value;
} elseif ($object->hasField($field)) {
- $options['order'][$alias . '.' . $field] = $value;
+ $options['order'][$object->alias . '.' . $field] = $value;
}
}
$vars = array('fields', 'order', 'limit', 'page', 'recursive');
View
18 cake/tests/cases/libs/controller/controller.test.php
@@ -1188,5 +1188,23 @@ function testRequestHandlerPrefers(){
$this->assertEqual($Controller->RequestHandler->prefers(), 'rss');
unset($Controller);
}
+
+/**
+ * Tests that the correct alias is selected
+ *
+ * @return void
+ */
+ function testValidateSortAlias() {
+ $Controller =& new Controller();
+ $Controller->uses = array('ControllerPost', 'ControllerComment');
+ $Controller->passedArgs[] = '1';
+ $Controller->params['url'] = array();
+ $Controller->constructClasses();
+ $Controller->passedArgs = array('sort' => 'Derp.id', 'direction' => 'asc');
+ $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
+ $this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1);
+ $this->assertEqual($results, array(1, 2, 3));
+ }
+
}
?>

0 comments on commit db39c24

Please sign in to comment.