diff --git a/integration/test/ParseQueryTest.js b/integration/test/ParseQueryTest.js index 20c6ae81b..763021000 100644 --- a/integration/test/ParseQueryTest.js +++ b/integration/test/ParseQueryTest.js @@ -1018,6 +1018,50 @@ describe('Parse Query', () => { }); }); + it('can includeAll nested objects', async () => { + const child1 = new TestObject({ foo: 'bar' }); + const child2 = new TestObject({ foo: 'baz' }); + const child3 = new TestObject({ foo: 'bin' }); + const parent = new Parse.Object('Container'); + parent.set('child1', child1); + parent.set('child2', child2); + parent.set('child3', child3); + await Parse.Object.saveAll([child1, child2, child3, parent]); + + const query = new Parse.Query('Container'); + query.equalTo('objectId', parent.id); + query.includeAll(); + + const results = await query.find(); + + assert.equal(results.length, 1); + const parentAgain = results[0]; + assert.equal(parentAgain.get('child1').get('foo'), 'bar'); + assert.equal(parentAgain.get('child2').get('foo'), 'baz'); + assert.equal(parentAgain.get('child3').get('foo'), 'bin'); + }); + + it('can includeAll nested objects in .each', async () => { + const child1 = new TestObject({ foo: 'bar' }); + const child2 = new TestObject({ foo: 'baz' }); + const child3 = new TestObject({ foo: 'bin' }); + const parent = new Parse.Object('Container'); + parent.set('child1', child1); + parent.set('child2', child2); + parent.set('child3', child3); + await Parse.Object.saveAll([child1, child2, child3, parent]); + + const query = new Parse.Query('Container'); + query.equalTo('objectId', parent.id); + query.includeAll(); + + await query.each((obj) => { + assert.equal(obj.get('child1').get('foo'), 'bar'); + assert.equal(obj.get('child2').get('foo'), 'baz'); + assert.equal(obj.get('child3').get('foo'), 'bin'); + }); + }); + it('can include nested objects via array', (done) => { let child = new TestObject(); let parent = new Parse.Object('Container'); diff --git a/src/ParseQuery.js b/src/ParseQuery.js index 91d0b6b75..af74aedc7 100644 --- a/src/ParseQuery.js +++ b/src/ParseQuery.js @@ -345,9 +345,11 @@ class ParseQuery { this._order = json.order.split(","); } - for (let key in json) if (json.hasOwnProperty(key)) { - if (["where", "include", "keys", "limit", "skip", "order"].indexOf(key) === -1) { - this._extraOptions[key] = json[key]; + for (let key in json) { + if (json.hasOwnProperty(key)) { + if (["where", "include", "keys", "limit", "skip", "order"].indexOf(key) === -1) { + this._extraOptions[key] = json[key]; + } } } @@ -1313,6 +1315,11 @@ class ParseQuery { /** * Includes nested Parse.Objects for the provided key. You can use dot * notation to specify which fields in the included object are also fetched. + * + * You can include all nested Parse.Objects by passing in '*'. + * Requires Parse Server 3.0.0+ + *
query.include('*');
+ * * @param {...String|Array} key The name(s) of the key(s) to include. * @return {Parse.Query} Returns the query, so you can chain this call. */ @@ -1327,6 +1334,17 @@ class ParseQuery { return this; } + /** + * Includes all nested Parse.Objects. + * + * Requires Parse Server 3.0.0+ + * + * @return {Parse.Query} Returns the query, so you can chain this call. + */ + includeAll(): ParseQuery { + return this.include('*'); + } + /** * Restricts the fields of the returned Parse.Objects to include only the * provided keys. If this is called multiple times, then all of the keys diff --git a/src/__tests__/ParseQuery-test.js b/src/__tests__/ParseQuery-test.js index 097d47191..d2e7396ed 100644 --- a/src/__tests__/ParseQuery-test.js +++ b/src/__tests__/ParseQuery-test.js @@ -899,6 +899,32 @@ describe('ParseQuery', () => { }); }); + it('can includeAll for pointers', () => { + const q = new ParseQuery('Item'); + q.includeAll(); + const json = q.toJSON(); + expect(json).toEqual({ + where: {}, + include: '*', + }); + const q2 = new ParseQuery('Item'); + q2.withJSON(json); + expect(q2._include).toEqual(['*']); + }); + + it('can use extraOptions', () => { + const q = new ParseQuery('Item'); + q._extraOptions.randomOption = 'test'; + const json = q.toJSON(); + expect(json).toEqual({ + where: {}, + randomOption: 'test', + }); + const q2 = new ParseQuery('Item'); + q2.withJSON(json); + expect(q2._extraOptions.randomOption).toBe('test'); + }); + it('can specify certain fields to send back', () => { var q = new ParseQuery('Item'); q.select('size'); @@ -1300,6 +1326,7 @@ describe('ParseQuery', () => { limit: 100, order: 'objectId', keys: 'size,name', + include: '*', where: { size: { $in: ['small', 'medium'] @@ -1338,6 +1365,7 @@ describe('ParseQuery', () => { ); q.equalTo('valid', true); q.select('size', 'name'); + q.includeAll(); var calls = 0; q.each((o) => {