Skip to content

Fixes #2221: Nested Or queries #2231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
});
});
6 changes: 4 additions & 2 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down