From cf273429b96c76db6ae454f23f8387cdb52609fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemen=20Dolin=C5=A1ek?= Date: Tue, 17 Oct 2023 13:53:53 +0200 Subject: [PATCH] MSSQL database doesn't allow aliases in GROUP BY --- src/Extension/FluentVersionedExtension.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Extension/FluentVersionedExtension.php b/src/Extension/FluentVersionedExtension.php index 9f1c6718..1aa6f8d4 100644 --- a/src/Extension/FluentVersionedExtension.php +++ b/src/Extension/FluentVersionedExtension.php @@ -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, @@ -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;