Browse Source

fix: child count doesnt include query

pull/6360/head
DarkPhoenix2704 1 year ago
parent
commit
0962da9795
  1. 14
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 11
      packages/nocodb/src/services/data-alias-nested.service.ts
  3. 11
      packages/nocodb/src/services/data-table.service.ts
  4. 11
      packages/nocodb/src/services/datas.service.ts
  5. 11
      packages/nocodb/src/services/public-datas.service.ts

14
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -1072,7 +1072,9 @@ class BaseModelSqlv2 {
return parentIds.map((id) => gs?.[id]?.[0] || []); return parentIds.map((id) => gs?.[id]?.[0] || []);
} }
public async mmListCount({ colId, parentId }) { public async mmListCount({ colId, parentId }, args) {
const { where } = this._getListArgs(args as any);
const relColumn = (await this.model.getColumns()).find( const relColumn = (await this.model.getColumns()).find(
(c) => c.id === colId, (c) => c.id === colId,
); );
@ -1106,12 +1108,12 @@ class BaseModelSqlv2 {
.select(cn) .select(cn)
// .where(parentTable.primaryKey.cn, id) // .where(parentTable.primaryKey.cn, id)
.where(_wherePk(parentTable.primaryKeys, parentId)), .where(_wherePk(parentTable.primaryKeys, parentId)),
) );
.first(); const aliasColObjMap = await childTable.getAliasColObjMap();
const filterObj = extractFilterFromXwhere(where, aliasColObjMap);
const { count } = await qb;
return count; await conditionV2(this, filterObj, qb);
return (await qb.first())?.count;
} }
// todo: naming & optimizing // todo: naming & optimizing

11
packages/nocodb/src/services/data-alias-nested.service.ts

@ -47,10 +47,13 @@ export class DataAliasNestedService {
}, },
param.query as any, param.query as any,
); );
const count: any = await baseModel.mmListCount({ const count: any = await baseModel.mmListCount(
colId: column.id, {
parentId: param.rowId, colId: column.id,
}); parentId: param.rowId,
},
param.query,
);
return new PagedResponseImpl(data, { return new PagedResponseImpl(data, {
count, count,

11
packages/nocodb/src/services/data-table.service.ts

@ -287,10 +287,13 @@ export class DataTableService {
}, },
listArgs as any, listArgs as any,
); );
count = (await baseModel.mmListCount({ count = (await baseModel.mmListCount(
colId: column.id, {
parentId: param.rowId, colId: column.id,
})) as number; parentId: param.rowId,
},
param.query,
)) as number;
} else if (colOptions.type === RelationTypes.HAS_MANY) { } else if (colOptions.type === RelationTypes.HAS_MANY) {
data = await baseModel.hmList( data = await baseModel.hmList(
{ {

11
packages/nocodb/src/services/datas.service.ts

@ -407,10 +407,13 @@ export class DatasService {
) )
)?.[key]; )?.[key];
const count: any = await baseModel.mmListCount({ const count: any = await baseModel.mmListCount(
colId: param.colId, {
parentId: param.rowId, colId: param.colId,
}); parentId: param.rowId,
},
param.query,
);
return new PagedResponseImpl(data, { return new PagedResponseImpl(data, {
count, count,

11
packages/nocodb/src/services/public-datas.service.ts

@ -473,10 +473,13 @@ export class PublicDatasService {
) )
)?.[key]; )?.[key];
const count: any = await baseModel.mmListCount({ const count: any = await baseModel.mmListCount(
colId: param.columnId, {
parentId: param.rowId, colId: param.columnId,
}); parentId: param.rowId,
},
param.query,
);
return new PagedResponseImpl(data, { ...param.query, count }); return new PagedResponseImpl(data, { ...param.query, count });
} }

Loading…
Cancel
Save