Browse Source

fix: handle empty & notempty for mm case

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

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

@ -172,6 +172,29 @@ const parseConditionV2 = async (
const mmParentColumn = await colOptions.getMMParentColumn();
const mmChildColumn = await colOptions.getMMChildColumn();
if (
filter.comparison_op === 'empty' ||
filter.comparison_op === 'notempty'
) {
const selectMmCount = knex(mmModel.table_name)
.count(mmChildColumn.column_name)
.where(
mmChildColumn.column_name,
knex.raw('??.??', [
alias || childModel.table_name,
childColumn.column_name,
])
);
return (qb) => {
if (filter.comparison_op === 'empty') {
qb.where(knex.raw('0'), selectMmCount);
} else {
qb.whereNot(knex.raw('0'), selectMmCount);
}
};
}
const selectQb = knex(mmModel.table_name)
.select(mmChildColumn.column_name)
.join(

Loading…
Cancel
Save