Skip to content

Commit

Permalink
BUGFIX Fixing SortColumn alias to be recognised by MSSQL/PGSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Harvey committed May 3, 2012
1 parent 521d436 commit 37369ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions model/DataQuery.php
Expand Up @@ -240,16 +240,16 @@ protected function ensureSelectContainsOrderbyColumns($query, $originalSelect =
// don't touch functions in the ORDER BY or function calls
// selected as fields
if(strpos($k, '(') !== false) continue;


$col = str_replace('"', '', trim($k));
$parts = explode('.', $col);

// Pull through SortColumn references from the originalSelect variables
if(preg_match('/_SortColumn/', $k)) {
if(isset($originalSelect[$k])) $query->selectField($originalSelect[$k], $k);
if(preg_match('/_SortColumn/', $col)) {
if(isset($originalSelect[$col])) $query->selectField($originalSelect[$col], $col);
continue;
}

$col = str_replace('"', '', trim($k));
$parts = explode('.', $col);

if(count($parts) == 1) {
$databaseFields = DataObject::database_fields($baseClass);

Expand Down
4 changes: 2 additions & 2 deletions model/SQLQuery.php
Expand Up @@ -383,9 +383,9 @@ public function orderby($clauses = null, $direction = null, $clear = true) {

$clause = trim($clause);
$column = "_SortColumn{$i}";

$this->selectField($clause, $column);
$this->orderby($column, $dir, false);
$this->orderby('"' . $column . '"', $dir, false);
$i++;
}
}
Expand Down

0 comments on commit 37369ab

Please sign in to comment.