Skip to content

Commit

Permalink
Merge branch 'developer'
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-deluna committed Aug 19, 2016
2 parents 34db1ee + d065a22 commit f08ce66
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
- nightly

Expand Down
4 changes: 4 additions & 0 deletions src/Query/Sql/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ public function orderBy($columns, $direction = 'asc')
{
$columns = $this->stringArgumentToArray($columns);
}
elseif ($columns instanceof Expression)
{
$this->orders[] = array($columns, $direction); return $this;
}

foreach ($columns as $key => $column)
{
Expand Down
11 changes: 11 additions & 0 deletions src/Translator/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,17 @@ protected function translateOrderBy()

foreach ($this->attr('orders') as $column => $direction)
{
// in case a raw value is given we had to
// put the column / raw value an direction inside another
// array because we cannot make objects to array keys.
if (is_array($direction))
{
// This only works in php 7 the php 5 fix is below
//list($column, $direction) = $direction;
$column = $direction[0];
$direction = $direction[1];
}

$build .= $this->escape($column) . ' ' . $direction . ', ';
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Query/Sql/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ public function testOrderBy()
$this->assertAttributes($this->createQuery()->orderBy(array('firstname' => 'asc', 'lastname' => 'desc')), array('orders' => array('firstname' => 'asc', 'lastname' => 'desc')));
}

/**
* Select::orderBy
*/
public function testOrderByRaw()
{
$raw = new Expression('language <> de');

// simple
$this->assertAttributes($this->createQuery()->orderBy($raw), array('orders' => array(array($raw, 'asc'))));
}

/**
* Select::groupBy
*/
Expand Down
6 changes: 6 additions & 0 deletions tests/Translator/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ public function testSelectOrderBy()
{
return $q->table('phpunit')->select()->orderBy(array('u.firstname' => 'asc', 'u.lastname' => 'desc'));
});

// raw sorting
$this->assertQueryTranslation('select * from `phpunit` order by firstname <> nick asc', array(), function($q)
{
return $q->table('phpunit')->select()->orderBy(new Expression("firstname <> nick"));
});
}

/**
Expand Down

0 comments on commit f08ce66

Please sign in to comment.