Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Making sure correct alias is selected for pagination

  • Loading branch information...
commit 8fc6b3fa9afc1e6859a138b4c86c0cb4d554caaf 1 parent f883840
@lorenzo lorenzo authored
View
2  cake/libs/controller/controller.php
@@ -1136,7 +1136,7 @@ function paginate($object = null, $scope = array(), $whitelist = array()) {
unset($options['order'][$key]);
if ($object->hasField($field)) {
- $options['order'][$alias . '.' . $field] = $value;
+ $options['order'][$object->alias . '.' . $field] = $value;
} elseif ($object->hasField($key, true)) {
$options['order'][$field] = $value;
} elseif (isset($object->{$alias}) && $object->{$alias}->hasField($field)) {
View
18 cake/tests/cases/libs/controller/controller.test.php
@@ -1525,4 +1525,22 @@ function testShutdownProcess() {
$MockedController->MockTest->expectCallCount('shutdown', 1);
$MockedController->shutdownProcess();
}
+
+/**
+ * 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));
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.