diff --git a/packages/nocodb/src/lib/dataMapper/lib/sql/conditionV2.ts b/packages/nocodb/src/lib/dataMapper/lib/sql/conditionV2.ts index d72dcea6a8..461619b324 100644 --- a/packages/nocodb/src/lib/dataMapper/lib/sql/conditionV2.ts +++ b/packages/nocodb/src/lib/dataMapper/lib/sql/conditionV2.ts @@ -203,12 +203,13 @@ const parseConditionV2 = async ( filter.comparison_op === 'notempty' ) filter.value = ''; - const field = customWhereClause + let field = customWhereClause ? filter.value : alias ? `${alias}.${column.column_name}` : column.column_name; - const val = customWhereClause ? customWhereClause : filter.value; + let val = customWhereClause ? customWhereClause : filter.value; + return qb => { switch (filter.comparison_op) { case 'eq': @@ -218,17 +219,29 @@ const parseConditionV2 = async ( qb = qb.whereNot(field, val); break; case 'like': + if (column.uidt === UITypes.Formula) { + [field, val] = [val, field]; + val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%') + } else { + val = `%${val}%`; + } qb = qb.where( field, qb?.client?.config?.client === 'pg' ? 'ilike' : 'like', - `%${val}%` + val ); break; case 'nlike': + if (column.uidt === UITypes.Formula) { + [field, val] = [val, field]; + val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%') + } else { + val = `%${val}%`; + } qb = qb.whereNot( field, qb?.client?.config?.client === 'pg' ? 'ilike' : 'like', - `%${val}%` + val ); break; case 'gt': @@ -273,9 +286,15 @@ const parseConditionV2 = async ( break; case 'empty': + if (column.uidt === UITypes.Formula) { + [field, val] = [val, field]; + } qb = qb.where(field, val); break; case 'notempty': + if (column.uidt === UITypes.Formula) { + [field, val] = [val, field]; + } qb = qb.whereNot(field, val); break; case 'null':