From df6bd61e33cabe8d95db180a6e7bf0dfb4f08c51 Mon Sep 17 00:00:00 2001 From: Justin Martin Date: Tue, 10 Jan 2023 15:35:35 +0100 Subject: [PATCH] fix(smart-field): smart-field search use returned query instead of mutability --- src/services/search-builder.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/services/search-builder.js b/src/services/search-builder.js index 1037a2976..99b603844 100644 --- a/src/services/search-builder.js +++ b/src/services/search-builder.js @@ -74,16 +74,17 @@ function SearchBuilder(model, opts, params, fieldNamesRequested) { // Retrocompatibility: customers which implement search on smart fields are expected to // inject their conditions at .where[Op.and][0][Op.or].push(searchCondition) // https://docs.forestadmin.com/documentation/reference-guide/fields/create-and-manage-smart-fields - const query = { + let query = { include: [], where: { [OPERATORS.AND]: [this.perform(associationName)] }, }; const fieldsWithSearch = schema.fields.filter((field) => field.search); + await Promise.all( fieldsWithSearch.map(async (field) => { try { - await field.search(query, params.search); + query = await field.search(query, params.search); } catch (error) { const errorMessage = `Cannot search properly on Smart Field ${field.field}: `; Interface.logger.error(errorMessage, error);