From 713bdde5ba7788b9f000317f7d88f8a9a6fbcc7b Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Wed, 13 Sep 2023 10:46:53 +0530 Subject: [PATCH] fix: incorrect row size in hm --- packages/nocodb/src/db/BaseModelSqlv2.ts | 14 +++++++++----- .../src/services/data-alias-nested.service.ts | 2 +- packages/nocodb/src/services/data-table.service.ts | 2 +- packages/nocodb/src/services/datas.service.ts | 2 +- .../nocodb/src/services/public-datas.service.ts | 11 +++++++---- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 24184e227b..b2b9088ff7 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -841,9 +841,10 @@ class BaseModelSqlv2 { } } - async hmListCount({ colId, id }) { + async hmListCount({ colId, id }, args) { try { // const { cn } = this.hasManyRelations.find(({ tn }) => tn === child) || {}; + const { where } = this._getListArgs(args as any); const relColumn = (await this.model.getColumns()).find( (c) => c.id === colId, ); @@ -867,10 +868,13 @@ class BaseModelSqlv2 { this.dbDriver(parentTn) .select(parentCol.column_name) .where(_wherePk(parentTable.primaryKeys, id)), - ) - .first(); - const { count } = await query; - return count; + ); + const aliasColObjMap = await childTable.getAliasColObjMap(); + const filterObj = extractFilterFromXwhere(where, aliasColObjMap); + + await conditionV2(this, filterObj, query); + + return (await query.first())?.count; } catch (e) { console.log(e); throw e; diff --git a/packages/nocodb/src/services/data-alias-nested.service.ts b/packages/nocodb/src/services/data-alias-nested.service.ts index 098db5b217..7271fb3889 100644 --- a/packages/nocodb/src/services/data-alias-nested.service.ts +++ b/packages/nocodb/src/services/data-alias-nested.service.ts @@ -223,7 +223,7 @@ export class DataAliasNestedService { const count = await baseModel.hmListCount({ colId: column.id, id: param.rowId, - }); + }, param.query); return new PagedResponseImpl(data, { count, diff --git a/packages/nocodb/src/services/data-table.service.ts b/packages/nocodb/src/services/data-table.service.ts index dc7b30d732..821f573c9b 100644 --- a/packages/nocodb/src/services/data-table.service.ts +++ b/packages/nocodb/src/services/data-table.service.ts @@ -305,7 +305,7 @@ export class DataTableService { count = (await baseModel.hmListCount({ colId: column.id, id: param.rowId, - })) as number; + }, param.query)) as number; } else { data = await baseModel.btRead( { diff --git a/packages/nocodb/src/services/datas.service.ts b/packages/nocodb/src/services/datas.service.ts index babc789206..af29428ec8 100644 --- a/packages/nocodb/src/services/datas.service.ts +++ b/packages/nocodb/src/services/datas.service.ts @@ -653,7 +653,7 @@ export class DatasService { const count = await baseModel.hmListCount({ colId: param.colId, id: param.rowId, - }); + }, param.query); return new PagedResponseImpl(data, { totalRows: count, diff --git a/packages/nocodb/src/services/public-datas.service.ts b/packages/nocodb/src/services/public-datas.service.ts index 8c54adfcfd..3f3367e1c4 100644 --- a/packages/nocodb/src/services/public-datas.service.ts +++ b/packages/nocodb/src/services/public-datas.service.ts @@ -546,10 +546,13 @@ export class PublicDatasService { ) )?.[key]; - const count = await baseModel.hmListCount({ - colId: param.columnId, - id: param.rowId, - }); + const count = await baseModel.hmListCount( + { + colId: param.columnId, + id: param.rowId, + }, + param.query, + ); return new PagedResponseImpl(data, { ...param.query, count }); }