From 431d864ac35c1ed66475c5992eca15f278af75a5 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Thu, 31 Mar 2016 20:38:34 -0400 Subject: [PATCH 1/2] :zap: reproduces #1302 --- spec/ParseQuery.spec.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/ParseQuery.spec.js b/spec/ParseQuery.spec.js index a2340e9eb6..206fe7f6bc 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -1494,6 +1494,36 @@ describe('Parse.Query testing', () => { }) }) + it('properly fetches nested pointers', (done) =>  { + let color = new Parse.Object('Color'); + color.set('hex','#133733'); + let circle = new Parse.Object('Circle'); + circle.set('radius', 1337); + + Parse.Object.saveAll([color, circle]).then(() => { + circle.set('color', color); + let badCircle = new Parse.Object('Circle'); + badCircle.id = 'badId'; + let complexFigure = new Parse.Object('ComplexFigure'); + complexFigure.set('consistsOf', [circle, badCircle]); + return complexFigure.save(); + }).then(() => { + let q = new Parse.Query('ComplexFigure'); + q.include('consistsOf.color'); + return q.find() + }).then((results) => { + expect(results.length).toBe(1); + let figure = results[0]; + expect(figure.get('consistsOf').length).toBe(1); + expect(figure.get('consistsOf')[0].get('color').get('hex')).toBe('#133733'); + done(); + }, (err) => { + fail('should not fail'); + done(); + }) + + }); + it("result object creation uses current extension", function(done) { var ParentObject = Parse.Object.extend({ className: "ParentObject" }); // Add a foo() method to ChildObject. From edfa4092c0b4cc4b326acdb64468be68eef04ec5 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Thu, 31 Mar 2016 20:24:18 -0400 Subject: [PATCH 2/2] :sunglasses: fixes #1302 - when including elements from an array of pointers, filters unaccessible/missing objects --- spec/ParseQuery.spec.js | 47 ++++++++++++++++++++++++++++++++++++++++- src/RestQuery.js | 3 ++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/spec/ParseQuery.spec.js b/spec/ParseQuery.spec.js index 206fe7f6bc..4537a0737e 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -1492,7 +1492,52 @@ describe('Parse.Query testing', () => { fail('should not fail'); done(); }) - }) + }); + + it('properly nested array of mixed objects with bad ids', (done) => { + let objects = []; + let total = 0; + while(objects.length != 5) { + let object = new Parse.Object('AnObject'); + object.set('key', objects.length); + objects.push(object); + } + while(objects.length != 10) { + let object = new Parse.Object('AnotherObject'); + object.set('key', objects.length); + objects.push(object); + } + Parse.Object.saveAll(objects).then(() => { + let object = new Parse.Object("AContainer"); + for (var i=0; i { + let query = new Parse.Query('AContainer'); + query.include('objects'); + return query.find() + }).then((results) => { + expect(results.length).toBe(1); + let res = results[0]; + let objects = res.get('objects'); + expect(objects.length).toBe(5); + objects.forEach((object) => { + total -= object.get('key'); + }); + expect(total).toBe(0); + done() + }, (err) => { + console.error(err); + fail('should not fail'); + done(); + }) + }); it('properly fetches nested pointers', (done) =>  { let color = new Parse.Object('Color'); diff --git a/src/RestQuery.js b/src/RestQuery.js index f2636b54c1..e825a5448c 100644 --- a/src/RestQuery.js +++ b/src/RestQuery.js @@ -537,7 +537,8 @@ function findPointers(object, path) { // pointers inflated. function replacePointers(object, path, replace) { if (object instanceof Array) { - return object.map((obj) => replacePointers(obj, path, replace)); + return object.map((obj) => replacePointers(obj, path, replace)) + .filter((obj) => obj != null && obj != undefined); } if (typeof object !== 'object') {