Skip to content

Commit

Permalink
Merge pull request #812 from t3hn0/7
Browse files Browse the repository at this point in the history
MSSQL database doesn't allow aliases in GROUP BY
  • Loading branch information
tractorcow authored Nov 14, 2023
2 parents 2eac537 + cf27342 commit 12a8d79
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 12a8d79

Please sign in to comment.