Skip to content

Commit a55466f

Browse files
flovilmartdrew-gross
authored andcommitted
Fixes #2221: Nested Or queries (#2231)
* Adds repro for #2221 * Fixes nested or queries * not for PG yet
1 parent 61aa5a8 commit a55466f

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

spec/ParseQuery.spec.js

+26
Original file line numberDiff line numberDiff line change
@@ -2529,4 +2529,30 @@ describe('Parse.Query testing', () => {
25292529
}
25302530
})
25312531
});
2532+
2533+
it_exclude_dbs(['postgres'])('properly handles nested ors', function(done) {
2534+
var objects = [];
2535+
while(objects.length != 4) {
2536+
var obj = new Parse.Object('Object');
2537+
obj.set('x', objects.length);
2538+
objects.push(obj)
2539+
}
2540+
Parse.Object.saveAll(objects).then(() => {
2541+
let q0 = new Parse.Query('Object');
2542+
q0.equalTo('x', 0);
2543+
let q1 = new Parse.Query('Object');
2544+
q1.equalTo('x', 1);
2545+
let q2 = new Parse.Query('Object');
2546+
q2.equalTo('x', 2);
2547+
let or01 = Parse.Query.or(q0,q1);
2548+
return Parse.Query.or(or01, q2).find();
2549+
}).then((results) => {
2550+
expect(results.length).toBe(3);
2551+
done();
2552+
}).catch((error) => {
2553+
fail('should not fail');
2554+
console.error(error);
2555+
done();
2556+
})
2557+
});
25322558
});

src/Controllers/DatabaseController.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,10 @@ DatabaseController.prototype.reduceInRelation = function(className, query, schem
540540
return Promise.all(ors.map((aQuery, index) => {
541541
return this.reduceInRelation(className, aQuery, schema).then((aQuery) => {
542542
query['$or'][index] = aQuery;
543-
})
544-
}));
543+
});
544+
})).then(() => {
545+
return Promise.resolve(query);
546+
});
545547
}
546548

547549
let promises = Object.keys(query).map((key) => {

0 commit comments

Comments
 (0)