Skip to content

Commit a74e8bd

Browse files
committed
Fixes issues with rest.each
1 parent dd66e7a commit a74e8bd

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

spec/rest.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,31 @@ describe('rest update', () => {
626626
});
627627
});
628628

629+
describe('rest each', () => {
630+
it('should iterate through all results', () => {
631+
const className = 'Yolo';
632+
const config = Config.get('test');
633+
const master = auth.master(config);
634+
let promise = Promise.resolve();
635+
let done = 0;
636+
while (done != 10) {
637+
done++;
638+
promise = promise.then(() => {
639+
return rest.create(config, auth, className, {});
640+
});
641+
}
642+
return promise.then(() => {
643+
let seen = 0;
644+
// use limit 1 to get them 1 by one
645+
return rest.each(config, master, className, {}, {limit: 1}, () => {
646+
seen++;
647+
}).then(() => {
648+
expect(seen).toBe(10);
649+
})
650+
}).then(done, done.fail);
651+
});
652+
})
653+
629654
describe('read-only masterKey', () => {
630655
it('properly throws on rest.create, rest.update and rest.del', () => {
631656
const config = Config.get('test');

src/rest.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function find(config, auth, className, restWhere, restOptions, clientSDK) {
3737

3838
function each(config, auth, className, where, options, callback) {
3939
options = Object.assign({}, options);
40+
options.order = 'objectId'; // force ordering on objectId
4041
where = Object.assign({}, where);
4142
let finished;
4243
return Parse.Promise._continueWhile(() => {
@@ -52,7 +53,7 @@ function each(config, auth, className, where, options, callback) {
5253
return callbacksDone.then(() => {
5354
if (results.length >= options.limit) {
5455
where['objectId'] = where['objectId'] || {};
55-
where['objectId']['$gt'] = results[results.length - 1].id;
56+
where['objectId']['$gt'] = results[results.length - 1].objectId;
5657
} else {
5758
finished = true;
5859
}

0 commit comments

Comments
 (0)