Skip to content

Commit

Permalink
Key sort the options before applying them.
Browse files Browse the repository at this point in the history
This fixes issues between page() and limit(). Page needs to be applied
after limit. There are other more fancy ways to implement this
dependency, but ksort() was the fastest solution.

Fixes #3159
  • Loading branch information
markstory committed Mar 30, 2014
1 parent 1c1b7e3 commit a74e74a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ORM/Query.php
Expand Up @@ -444,6 +444,7 @@ public function applyOptions(array $options) {
'page' => 'page',
];

ksort($options);
foreach ($options as $option => $values) {
if (isset($valid[$option]) && isset($values)) {
$this->{$valid[$option]}($values);
Expand Down
17 changes: 17 additions & 0 deletions tests/TestCase/ORM/QueryTest.php
Expand Up @@ -792,6 +792,23 @@ public function testApplyOptions() {
$this->assertEquals($expected, $query->contain());
}

/**
* Test that page is applied after limit.
*
* @return void
*/
public function testApplyOptionsPageIsLast() {
$query = new Query($this->connection, $this->table);
$opts = [
'page' => 3,
'limit' => 5
];
$query->applyOptions($opts);
$this->assertEquals(5, $query->clause('limit'));
$this->assertEquals(10, $query->clause('offset'));
}


/**
* ApplyOptions should ignore null values.
*
Expand Down

0 comments on commit a74e74a

Please sign in to comment.