Browse Source

wip: handle empty & not empty for hm

pull/2535/head
Wing-Kam Wong 2 years ago
parent
commit
7415f7f584
  1. 25
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

25
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

@ -87,6 +87,31 @@ const parseConditionV2 = async (
const parentModel = await parentColumn.getModel(); const parentModel = await parentColumn.getModel();
await parentModel.getColumns(); await parentModel.getColumns();
if (colOptions.type === RelationTypes.HAS_MANY) { if (colOptions.type === RelationTypes.HAS_MANY) {
if (
filter.comparison_op === 'empty' ||
filter.comparison_op === 'notempty'
) {
const selectParentQb = knex(parentModel.table_name);
console.log('HERE1');
console.log(selectParentQb.toQuery());
const selectHmCount = knex(childModel.table_name)
.select(childColumn.column_name)
.count(childColumn.column_name)
.whereNotNull(childColumn.column_name)
.groupBy(childColumn.column_name);
console.log('HERE2');
console.log(selectHmCount.toQuery());
const q = selectParentQb.leftJoin(
selectHmCount.as('t2'),
parentModel.table_name + '.' + parentColumn.column_name,
't2.' + childColumn.column_name
);
console.log('HERE3');
console.log(q.toQuery());
return q;
}
const selectQb = knex(childModel.table_name).select( const selectQb = knex(childModel.table_name).select(
childColumn.column_name childColumn.column_name
); );

Loading…
Cancel
Save