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] || []);
}
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(
(c) => c.id === colId,
);
@ -1106,12 +1108,12 @@ class BaseModelSqlv2 {
.select(cn)
// .where(parentTable.primaryKey.cn, id)
.where(_wherePk(parentTable.primaryKeys, parentId)),
)
.first();
const { count } = await qb;
);
const aliasColObjMap = await childTable.getAliasColObjMap();
const filterObj = extractFilterFromXwhere(where, aliasColObjMap);
return count;
await conditionV2(this, filterObj, qb);
return (await qb.first())?.count;
}
// todo: naming & optimizing

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

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

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

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

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

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

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

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

Loading…
Cancel
Save