Skip to content

Commit

Permalink
Fix for Database::_sort (UnionOfRAD#986). Will not output ORDER BY cl…
Browse files Browse the repository at this point in the history
…ause if given field is empty (ie. if = array()).

Updated a test case.
  • Loading branch information
Marc Ghorayeb committed Jul 16, 2013
1 parent 81c873a commit 218081c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data/source/Database.php
Expand Up @@ -1243,7 +1243,7 @@ protected function _sort($field, $context, $clause = 'ORDER BY', $direction = tr
$field = array($field => $direction);
}

if (!is_array($field)) {
if (!is_array($field) || empty($field)) {
return;
}
$result = array();
Expand Down
4 changes: 4 additions & 0 deletions tests/cases/data/source/DatabaseTest.php
Expand Up @@ -607,6 +607,10 @@ public function testOrder() {
$result = $this->_db->order(array('author_id', "title" => "DESC"), $query);
$expected = 'ORDER BY {MockDatabasePost}.{author_id} ASC, {MockDatabasePost}.{title} DESC';
$this->assertEqual($expected, $result);

$result = $this->_db->order(array(), $query);
$expected = '';
$this->assertEqual($expected, $result);
}

public function testOrderOnRelated() {
Expand Down

0 comments on commit 218081c

Please sign in to comment.