Fixes #2221: Nested Or queries (#2231)

* Adds repro for #2221

* Fixes nested or queries

* not for PG yet
This commit is contained in:
Florent Vilmart
2016-07-09 01:03:13 -04:00
committed by Drew
parent 61aa5a8d62
commit a55466fde8
2 changed files with 30 additions and 2 deletions

View File

@@ -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();
})
});
}); });

View File

@@ -540,8 +540,10 @@ DatabaseController.prototype.reduceInRelation = function(className, query, schem
return Promise.all(ors.map((aQuery, index) => { return Promise.all(ors.map((aQuery, index) => {
return this.reduceInRelation(className, aQuery, schema).then((aQuery) => { return this.reduceInRelation(className, aQuery, schema).then((aQuery) => {
query['$or'][index] = aQuery; query['$or'][index] = aQuery;
}) });
})); })).then(() => {
return Promise.resolve(query);
});
} }
let promises = Object.keys(query).map((key) => { let promises = Object.keys(query).map((key) => {