From 6c66d7778904b3640bca44f4c9c9c884404e9655 Mon Sep 17 00:00:00 2001 From: Kingtous Date: Sat, 23 Oct 2021 11:17:16 +0800 Subject: [PATCH] fix: add $and incursive process --- src/Controllers/DatabaseController.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Controllers/DatabaseController.js b/src/Controllers/DatabaseController.js index be2e61ab42..b1883466a7 100644 --- a/src/Controllers/DatabaseController.js +++ b/src/Controllers/DatabaseController.js @@ -971,6 +971,18 @@ class DatabaseController { return Promise.resolve(query); }); } + if (query['$and']) { + const ors = query['$and']; + return Promise.all( + ors.map((aQuery, index) => { + return this.reduceInRelation(className, aQuery, schema).then(aQuery => { + query['$and'][index] = aQuery; + }); + }) + ).then(() => { + return Promise.resolve(query); + }); + } const promises = Object.keys(query).map(key => { const t = schema.getExpectedType(className, key); @@ -1049,7 +1061,13 @@ class DatabaseController { }) ); } - + if (query['$and']) { + return Promise.all( + query['$or'].map(aQuery => { + return this.reduceRelationKeys(className, aQuery, queryOptions); + }) + ); + } var relatedTo = query['$relatedTo']; if (relatedTo) { return this.relatedIds(