diff --git a/spec/ParseQuery.spec.js b/spec/ParseQuery.spec.js index 81b4da1e..d29054d2 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -2529,4 +2529,30 @@ describe('Parse.Query testing', () => { } }) }); + + it_exclude_dbs(['postgres'])('properly handles nested ors', function(done) { + var objects = []; + while(objects.length != 4) { + var obj = new Parse.Object('Object'); + obj.set('x', objects.length); + objects.push(obj) + } + Parse.Object.saveAll(objects).then(() => { + let q0 = new Parse.Query('Object'); + q0.equalTo('x', 0); + let q1 = new Parse.Query('Object'); + q1.equalTo('x', 1); + let q2 = new Parse.Query('Object'); + q2.equalTo('x', 2); + let or01 = Parse.Query.or(q0,q1); + return Parse.Query.or(or01, q2).find(); + }).then((results) => { + expect(results.length).toBe(3); + done(); + }).catch((error) => { + fail('should not fail'); + console.error(error); + done(); + }) + }); }); diff --git a/src/Controllers/DatabaseController.js b/src/Controllers/DatabaseController.js index 074f4f25..811f9b0a 100644 --- a/src/Controllers/DatabaseController.js +++ b/src/Controllers/DatabaseController.js @@ -540,8 +540,10 @@ DatabaseController.prototype.reduceInRelation = function(className, query, schem return Promise.all(ors.map((aQuery, index) => { return this.reduceInRelation(className, aQuery, schema).then((aQuery) => { query['$or'][index] = aQuery; - }) - })); + }); + })).then(() => { + return Promise.resolve(query); + }); } let promises = Object.keys(query).map((key) => {