From 568c285369717ef5423e63304291016b41daca5d Mon Sep 17 00:00:00 2001 From: Corey Date: Wed, 11 Nov 2020 11:57:41 -0500 Subject: [PATCH] Fix includeAll for querying a Pointer and Pointer array (#7002) * initial test * Add failing testcase * fix includeAll by considering array --- spec/ParseQuery.spec.js | 84 +++++++++++++++++++++++++++++++++++++++++ src/RestQuery.js | 5 ++- 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/spec/ParseQuery.spec.js b/spec/ParseQuery.spec.js index 5b8581dc93..846818fc9f 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -4008,6 +4008,90 @@ describe('Parse.Query testing', () => { }); }); + it('include pointer and pointer array', function (done) { + const child = new TestObject(); + const child2 = new TestObject(); + child.set('foo', 'bar'); + child2.set('hello', 'world'); + Parse.Object.saveAll([child, child2]).then(function () { + const parent = new Container(); + parent.set('child', child.toPointer()); + parent.set('child2', [child2.toPointer()]); + parent.save().then(function () { + const query = new Parse.Query(Container); + query.include(['child', 'child2']); + query.find().then(function (results) { + equal(results.length, 1); + const parentAgain = results[0]; + const childAgain = parentAgain.get('child'); + ok(childAgain); + equal(childAgain.get('foo'), 'bar'); + const child2Again = parentAgain.get('child2'); + equal(child2Again.length, 1); + ok(child2Again); + equal(child2Again[0].get('hello'), 'world'); + done(); + }); + }); + }); + }); + + it('include pointer and pointer array (keys switched)', function (done) { + const child = new TestObject(); + const child2 = new TestObject(); + child.set('foo', 'bar'); + child2.set('hello', 'world'); + Parse.Object.saveAll([child, child2]).then(function () { + const parent = new Container(); + parent.set('child', child.toPointer()); + parent.set('child2', [child2.toPointer()]); + parent.save().then(function () { + const query = new Parse.Query(Container); + query.include(['child2', 'child']); + query.find().then(function (results) { + equal(results.length, 1); + const parentAgain = results[0]; + const childAgain = parentAgain.get('child'); + ok(childAgain); + equal(childAgain.get('foo'), 'bar'); + const child2Again = parentAgain.get('child2'); + equal(child2Again.length, 1); + ok(child2Again); + equal(child2Again[0].get('hello'), 'world'); + done(); + }); + }); + }); + }); + + it('includeAll pointer and pointer array', function (done) { + const child = new TestObject(); + const child2 = new TestObject(); + child.set('foo', 'bar'); + child2.set('hello', 'world'); + Parse.Object.saveAll([child, child2]).then(function () { + const parent = new Container(); + parent.set('child', child.toPointer()); + parent.set('child2', [child2.toPointer()]); + parent.save().then(function () { + const query = new Parse.Query(Container); + query.includeAll(); + query.find().then(function (results) { + equal(results.length, 1); + const parentAgain = results[0]; + const childAgain = parentAgain.get('child'); + ok(childAgain); + equal(childAgain.get('foo'), 'bar'); + const child2Again = parentAgain.get('child2'); + equal(child2Again.length, 1); + ok(child2Again); + equal(child2Again[0].get('hello'), 'world'); + done(); + }); + }); + }); + }); + it('select nested keys 2 level includeAll', done => { const Foobar = new Parse.Object('Foobar'); const BarBaz = new Parse.Object('Barbaz'); diff --git a/src/RestQuery.js b/src/RestQuery.js index ec43992a07..78fd022bc1 100644 --- a/src/RestQuery.js +++ b/src/RestQuery.js @@ -676,7 +676,10 @@ RestQuery.prototype.handleIncludeAll = function () { const includeFields = []; const keyFields = []; for (const field in schema.fields) { - if (schema.fields[field].type && schema.fields[field].type === 'Pointer') { + if ( + (schema.fields[field].type && schema.fields[field].type === 'Pointer') || + (schema.fields[field].type && schema.fields[field].type === 'Array') + ) { includeFields.push([field]); keyFields.push(field); }