Skip to content

Fixes issue affecting sorting in beforeFind #4519

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 2 commits into from
Jan 24, 2018
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/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,32 @@ describe('beforeFind hooks', () => {
});
});

it('should handle sorting where', (done) => {
Parse.Cloud.beforeFind('MyObject', (req) => {
const query = req.query;
query.ascending('score');
return query;
});

const count = 20;
const objects = [];
while (objects.length != count) {
const object = new Parse.Object('MyObject');
object.set('score', Math.floor(Math.random() * 100));
objects.push(object);
}
Parse.Object.saveAll(objects).then(() => {
const query = new Parse.Query('MyObject');
return query.find();
}).then((objects) => {
let lastScore = -1;
objects.forEach((element) => {
expect(element.get('score') >= lastScore).toBe(true);
lastScore = element.get('score');
});
}).then(done).catch(done.fail);
});

it('should add beforeFind trigger using get API',(done) => {
const hook = {
method: function(req) {
Expand Down
4 changes: 4 additions & 0 deletions src/triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ export function maybeRunQueryTrigger(triggerType, className, restWhere, restOpti
restOptions = restOptions || {};
restOptions.keys = jsonQuery.keys;
}
if (jsonQuery.order) {
restOptions = restOptions || {};
restOptions.order = jsonQuery.order;
}
if (requestObject.readPreference) {
restOptions = restOptions || {};
restOptions.readPreference = requestObject.readPreference;
Expand Down