Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit 1bed3da

Browse files
author
Nik Barham
committed
QueryBuilder: Fixing error when sorting by multiple columns
1 parent b64c17c commit 1bed3da

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Automatorm/Database/QueryBuilder.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,16 @@ public function resolveLimit()
386386

387387
public function resolveSort()
388388
{
389-
if (!$this->sortBy) return '';
389+
$sortlist = [];
390+
foreach ($this->sortBy as $sort) {
391+
if ($sort['sort']) $sortlist[] = $this->escapeColumn($sort['sort']) . ' ' . $sort['dir'];
392+
}
390393

391-
$string = ' ORDER BY ';
392-
foreach ($this->sortBy as $sort)
393-
{
394-
if ($sort['sort']) $string .= $this->escapeColumn($sort['sort']) . ' ' . $sort['dir'];
394+
if ($sortlist) {
395+
return ' ORDER BY ' . implode(', ', $sortlist);
395396
}
396397

397-
return $string;
398+
return '';
398399
}
399400

400401
public function escapeTable($table)

0 commit comments

Comments
 (0)