Skip to content

Commit edfa409

Browse files
committed
😎 fixes #1302
- when including elements from an array of pointers, filters unaccessible/missing objects
1 parent 431d864 commit edfa409

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

spec/ParseQuery.spec.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,52 @@ describe('Parse.Query testing', () => {
14921492
fail('should not fail');
14931493
done();
14941494
})
1495-
})
1495+
});
1496+
1497+
it('properly nested array of mixed objects with bad ids', (done) => {
1498+
let objects = [];
1499+
let total = 0;
1500+
while(objects.length != 5) {
1501+
let object = new Parse.Object('AnObject');
1502+
object.set('key', objects.length);
1503+
objects.push(object);
1504+
}
1505+
while(objects.length != 10) {
1506+
let object = new Parse.Object('AnotherObject');
1507+
object.set('key', objects.length);
1508+
objects.push(object);
1509+
}
1510+
Parse.Object.saveAll(objects).then(() => {
1511+
let object = new Parse.Object("AContainer");
1512+
for (var i=0; i<objects.length; i++) {
1513+
if (i%2 == 0) {
1514+
objects[i].id = 'randomThing'
1515+
} else {
1516+
total += objects[i].get('key');
1517+
}
1518+
}
1519+
object.set('objects', objects);
1520+
return object.save();
1521+
}).then(() => {
1522+
let query = new Parse.Query('AContainer');
1523+
query.include('objects');
1524+
return query.find()
1525+
}).then((results) => {
1526+
expect(results.length).toBe(1);
1527+
let res = results[0];
1528+
let objects = res.get('objects');
1529+
expect(objects.length).toBe(5);
1530+
objects.forEach((object) => {
1531+
total -= object.get('key');
1532+
});
1533+
expect(total).toBe(0);
1534+
done()
1535+
}, (err) => {
1536+
console.error(err);
1537+
fail('should not fail');
1538+
done();
1539+
})
1540+
});
14961541

14971542
it('properly fetches nested pointers', (done) =>  {
14981543
let color = new Parse.Object('Color');

src/RestQuery.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ function findPointers(object, path) {
537537
// pointers inflated.
538538
function replacePointers(object, path, replace) {
539539
if (object instanceof Array) {
540-
return object.map((obj) => replacePointers(obj, path, replace));
540+
return object.map((obj) => replacePointers(obj, path, replace))
541+
.filter((obj) => obj != null && obj != undefined);
541542
}
542543

543544
if (typeof object !== 'object') {

0 commit comments

Comments
 (0)