Skip to content

Commit fbb9770

Browse files
Clear existing ordering when groupBy is active
MySQL's ONLY_FULL_GROUP_BY mode rejects ORDER BY clauses that reference non-aggregated columns not in the GROUP BY. Use reorder() to clear inherited ordering and default to ordering by the group column. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4db28aa commit fbb9770

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/ReportBuilder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ public function rowsQuery()
3838
? $this->resolveColumnWithJoins($query, $this->aggregateColumn)
3939
: "{$baseTable}.{$this->aggregateColumn}";
4040

41-
$query->selectRaw("{$groupByColumn} as group_value, {$this->aggregateFunction}({$aggregateColumn}) as aggregate")
42-
->groupBy($groupByColumn);
41+
$query->reorder()
42+
->selectRaw("{$groupByColumn} as group_value, {$this->aggregateFunction}({$aggregateColumn}) as aggregate")
43+
->groupBy($groupByColumn)
44+
->orderBy($groupByColumn);
4345

4446
return $query;
4547
}

0 commit comments

Comments
 (0)