From 7a452685325b1cecdc1c04598ac77f43b41235d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20FENAUX?= Date: Tue, 31 Aug 2021 17:19:57 +0200 Subject: [PATCH] filters-parsers update to all filters on smart fields with belongsTo relationship --- src/services/filters-parser.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/services/filters-parser.js b/src/services/filters-parser.js index 2011b7af6..0f650b89b 100644 --- a/src/services/filters-parser.js +++ b/src/services/filters-parser.js @@ -18,8 +18,11 @@ function FiltersParser(modelSchema, timezone, options) { this.formatCondition = async (condition) => { const isTextField = this.isTextField(condition.field); + if (this.isSmartField(modelSchema, condition.field)) { - const fieldFound = modelSchema.fields.find((field) => field.field === condition.field); + const fieldFound = modelSchema.fields.find(function (field) { + return (!!field.isVirtual && field.field === condition.field) || (!!field.reference && field.field === condition.field.split(':')[0]); + }); if (!fieldFound.filter) throw new Error(`"filter" method missing on smart field "${fieldFound.field}"`); @@ -123,7 +126,9 @@ function FiltersParser(modelSchema, timezone, options) { }; this.isSmartField = (schema, fieldName) => { - const fieldFound = schema.fields.find((field) => field.field === fieldName); + const fieldFound = schema.fields.find(function (field) { + return (!!field.isVirtual && field.field === fieldName) || (!!field.reference && field.field === fieldName.split(':')[0]); + }); return !!fieldFound && !!fieldFound.isVirtual; };