From d95871142e6570004e13e67067b9d31276a4a52a Mon Sep 17 00:00:00 2001 From: Dan Niculescu <47105105+DanAlexandruNiculescu@users.noreply.github.com> Date: Tue, 26 Jul 2022 13:31:53 +0200 Subject: [PATCH 1/3] Update FindQueryBuilder.js - GroupBy key column added as a default - GroupBy parameter is added only if there are joins --- lib/FindQueryBuilder.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/FindQueryBuilder.js b/lib/FindQueryBuilder.js index 4a64bac..7d02828 100644 --- a/lib/FindQueryBuilder.js +++ b/lib/FindQueryBuilder.js @@ -437,10 +437,14 @@ class FindQueryBuilder { */ _buildGroupBy(params, builder) { const groupByParam = _.find(params, { key: 'groupBy' }); - if (groupByParam) { - builder.select(groupByParam.value.split(',')); + const joinParam = _.find(builder._operations, { name: 'innerJoin' }); + const keyColumn = this._modelClass.keyColumn; + + if (groupByParam && joinParam) { builder.groupBy(groupByParam.value.split(',')); + return; } + keyColumn && builder.groupBy(keyColumn.split(',')); } /** From 5213075f3f7e6d94f199cf41d5cf7204831c483c Mon Sep 17 00:00:00 2001 From: Dan Niculescu <47105105+DanAlexandruNiculescu@users.noreply.github.com> Date: Tue, 26 Jul 2022 15:47:19 +0200 Subject: [PATCH 2/3] key column replaced with id column --- lib/FindQueryBuilder.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/FindQueryBuilder.js b/lib/FindQueryBuilder.js index 7d02828..58da25a 100644 --- a/lib/FindQueryBuilder.js +++ b/lib/FindQueryBuilder.js @@ -438,13 +438,13 @@ class FindQueryBuilder { _buildGroupBy(params, builder) { const groupByParam = _.find(params, { key: 'groupBy' }); const joinParam = _.find(builder._operations, { name: 'innerJoin' }); - const keyColumn = this._modelClass.keyColumn; + const idColumn = this._modelClass.idColumn; if (groupByParam && joinParam) { builder.groupBy(groupByParam.value.split(',')); return; } - keyColumn && builder.groupBy(keyColumn.split(',')); + idColumn && builder.groupBy(idColumn.split(',')); } /** From f2afc834f4b52058902fd157cdec0db8cfd386c1 Mon Sep 17 00:00:00 2001 From: Dan Niculescu <47105105+DanAlexandruNiculescu@users.noreply.github.com> Date: Tue, 26 Jul 2022 16:39:45 +0200 Subject: [PATCH 3/3] Update FindQueryBuilder.js --- lib/FindQueryBuilder.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/FindQueryBuilder.js b/lib/FindQueryBuilder.js index 58da25a..80ffc4a 100644 --- a/lib/FindQueryBuilder.js +++ b/lib/FindQueryBuilder.js @@ -440,11 +440,11 @@ class FindQueryBuilder { const joinParam = _.find(builder._operations, { name: 'innerJoin' }); const idColumn = this._modelClass.idColumn; - if (groupByParam && joinParam) { + if (groupByParam) { builder.groupBy(groupByParam.value.split(',')); - return; + } else if (joinParam) { + builder.groupBy(Array.isArray(idColumn) ? idColumn : idColumn.split(',')); } - idColumn && builder.groupBy(idColumn.split(',')); } /**