Browse Source

fix(nocodb): handle self reference

pull/5230/head
Wing-Kam Wong 2 years ago
parent
commit
83e8f75ab8
  1. 39
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

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

@ -91,6 +91,19 @@ const parseConditionV2 = async (
await parentModel.getColumns(); await parentModel.getColumns();
if (colOptions.type === RelationTypes.HAS_MANY) { if (colOptions.type === RelationTypes.HAS_MANY) {
if (['blank', 'notblank'].includes(filter.comparison_op)) { if (['blank', 'notblank'].includes(filter.comparison_op)) {
// handle self reference
if (parentModel.id === childModel.id) {
if (filter.comparison_op === 'blank') {
return (qb) => {
qb.whereNull(childColumn.column_name);
};
} else {
return (qb) => {
qb.whereNotNull(childColumn.column_name);
};
}
}
const selectHmCount = knex(childModel.table_name) const selectHmCount = knex(childModel.table_name)
.count(childColumn.column_name) .count(childColumn.column_name)
.where( .where(
@ -134,6 +147,19 @@ const parseConditionV2 = async (
}; };
} else if (colOptions.type === RelationTypes.BELONGS_TO) { } else if (colOptions.type === RelationTypes.BELONGS_TO) {
if (['blank', 'notblank'].includes(filter.comparison_op)) { if (['blank', 'notblank'].includes(filter.comparison_op)) {
// handle self reference
if (parentModel.id === childModel.id) {
if (filter.comparison_op === 'blank') {
return (qb) => {
qb.whereNull(childColumn.column_name);
};
} else {
return (qb) => {
qb.whereNotNull(childColumn.column_name);
};
}
}
const selectBtCount = knex(parentModel.table_name) const selectBtCount = knex(parentModel.table_name)
.count(parentColumn.column_name) .count(parentColumn.column_name)
.where( .where(
@ -182,6 +208,19 @@ const parseConditionV2 = async (
const mmChildColumn = await colOptions.getMMChildColumn(); const mmChildColumn = await colOptions.getMMChildColumn();
if (['blank', 'notblank'].includes(filter.comparison_op)) { if (['blank', 'notblank'].includes(filter.comparison_op)) {
// handle self reference
if (mmModel.id === childModel.id) {
if (filter.comparison_op === 'blank') {
return (qb) => {
qb.whereNull(childColumn.column_name);
};
} else {
return (qb) => {
qb.whereNotNull(childColumn.column_name);
};
}
}
const selectMmCount = knex(mmModel.table_name) const selectMmCount = knex(mmModel.table_name)
.count(mmChildColumn.column_name) .count(mmChildColumn.column_name)
.where( .where(

Loading…
Cancel
Save