Skip to content

Commit

Permalink
MSSQL database doesn't allow aliases in GROUP BY
Browse files Browse the repository at this point in the history
  • Loading branch information
t3hn0 committed Oct 17, 2023
1 parent 2eac537 commit cf27342
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Extension/FluentVersionedExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,11 @@ protected function getCurrentVersionNumbers(string $class, string $stage, ?array
? sprintf(' AND "BaseTable"."RecordID" IN (%s)', DB::placeholders($ids))
: '';

$sql = 'SELECT "BaseTable"."RecordID" as "LatestID", MAX("%1$s"."Version") as "LatestVersion" FROM "%2$s" AS "BaseTable"'
$sql = 'SELECT "BaseTable"."RecordID", MAX("%1$s"."Version") as "LatestVersion" FROM "%2$s" AS "BaseTable"'
. ' INNER JOIN "%1$s" ON "BaseTable"."RecordID" = "%1$s"."RecordID" AND "%1$s"."Locale" = ?'
. ' INNER JOIN "%3$s" ON "%3$s"."RecordID" = "%1$s"."RecordID" AND "%3$s"."Version" = "%1$s"."Version"'
. ' WHERE "BaseTable"."Locale" = ?%4$s%5$s'
. ' GROUP BY "LatestID"';
. ' GROUP BY "BaseTable"."RecordID"';

$query = sprintf(
$sql,
Expand All @@ -950,7 +950,7 @@ protected function getCurrentVersionNumbers(string $class, string $stage, ?array
$versions = [];

foreach ($results as $result) {
$id = (int) $result['LatestID'];
$id = (int) $result['RecordID'];
$version = (int) $result['LatestVersion'];

$versions[$id] = $version;
Expand Down

0 comments on commit cf27342

Please sign in to comment.