From 0ef7c854ab126435a3cbb64bbac06e3fabeaf1f4 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 16 Nov 2023 12:24:13 +0000 Subject: [PATCH] fix: support qrcode and barcode group by --- packages/nocodb/src/db/BaseModelSqlv2.ts | 28 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index cac564a863..8734bbe296 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -559,14 +559,22 @@ class BaseModelSqlv2 { await Promise.all( args.column_name.split(',').map(async (col) => { - const column = cols.find( - (c) => c.column_name === col || c.title === col, - ); - groupByColumns[column.id] = column; + let column = cols.find((c) => c.column_name === col || c.title === col); if (!column) { throw NcError.notFound('Column not found'); } + // if qrCode or Barcode replace it with value column nd keep the alias + if ([UITypes.QrCode, UITypes.Barcode].includes(column.uidt)) + column = new Column({ + ...(await column + .getColOptions() + .then((col) => col.getValueColumn())), + title: column.title, + }); + + groupByColumns[column.id] = column; + switch (column.uidt) { case UITypes.Links: case UITypes.Rollup: @@ -723,16 +731,26 @@ class BaseModelSqlv2 { const groupBySelectors = []; const getAlias = getAliasGenerator('__nc_gb'); + // todo: refactor and avoid duplicate code await this.model.getColumns().then((cols) => Promise.all( args.column_name.split(',').map(async (col) => { - const column = cols.find( + let column = cols.find( (c) => c.column_name === col || c.title === col, ); if (!column) { throw NcError.notFound('Column not found'); } + // if qrCode or Barcode replace it with value column nd keep the alias + if ([UITypes.QrCode, UITypes.Barcode].includes(column.uidt)) + column = new Column({ + ...(await column + .getColOptions() + .then((col) => col.getValueColumn())), + title: column.title, + }); + switch (column.uidt) { case UITypes.Rollup: case UITypes.Links: