From 27f8e22e8d7b6a2e555a9dfb21532641ededc465 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 11 Feb 2023 17:31:23 +0800 Subject: [PATCH] fix(nocodb): attachment filter logic --- .../db/sql-data-mapper/lib/sql/conditionV2.ts | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts index 889c284b43..b806ad24ea 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts @@ -357,9 +357,16 @@ const parseConditionV2 = async ( break; case 'like': if (!val) { - // val is empty -> all values including empty strings but NULL - qb.where(field, ''); - qb.orWhereNotNull(field); + if (column.uidt === UITypes.Attachment) { + qb = qb + .orWhereNull(field) + .orWhere(field, '[]') + .orWhere(field, 'null'); + } else { + // val is empty -> all values including empty strings but NULL + qb.where(field, ''); + qb.orWhereNotNull(field); + } } else { if (column.uidt === UITypes.Formula) { [field, val] = [val, field]; @@ -377,9 +384,15 @@ const parseConditionV2 = async ( break; case 'nlike': if (!val) { - // val is empty -> all values including NULL but empty strings - qb.whereNot(field, ''); - qb.orWhereNull(field); + if (column.uidt === UITypes.Attachment) { + qb.whereNot(field, '') + .whereNot(field, 'null') + .whereNot(field, '[]'); + } else { + // val is empty -> all values including NULL but empty strings + qb.whereNot(field, ''); + qb.orWhereNull(field); + } } else { if (column.uidt === UITypes.Formula) { [field, val] = [val, field]; @@ -540,12 +553,26 @@ const parseConditionV2 = async ( qb = qb.whereNotNull(customWhereClause || field); break; case 'blank': - qb = qb.whereNull(customWhereClause || field).orWhere(field, ''); + if (column.uidt === UITypes.Attachment) { + qb = qb + .whereNull(customWhereClause || field) + .orWhere(field, '[]') + .orWhere(field, 'null'); + } else { + qb = qb.whereNull(customWhereClause || field).orWhere(field, ''); + } break; case 'notblank': - qb = qb - .whereNotNull(customWhereClause || field) - .whereNot(field, ''); + if (column.uidt === UITypes.Attachment) { + qb = qb + .whereNotNull(customWhereClause || field) + .whereNot(field, '[]') + .whereNot(field, 'null'); + } else { + qb = qb + .whereNotNull(customWhereClause || field) + .whereNot(field, ''); + } break; case 'checked': qb = qb.where(customWhereClause || field, true);