Skip to content

Commit 000c1fb

Browse files
authored
Support includeAll Query (#632)
* includeAll * added * to include * removed unnessary fields * include server version
1 parent 6d5112a commit 000c1fb

File tree

3 files changed

+93
-3
lines changed

3 files changed

+93
-3
lines changed

integration/test/ParseQueryTest.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,50 @@ describe('Parse Query', () => {
10181018
});
10191019
});
10201020

1021+
it('can includeAll nested objects', async () => {
1022+
const child1 = new TestObject({ foo: 'bar' });
1023+
const child2 = new TestObject({ foo: 'baz' });
1024+
const child3 = new TestObject({ foo: 'bin' });
1025+
const parent = new Parse.Object('Container');
1026+
parent.set('child1', child1);
1027+
parent.set('child2', child2);
1028+
parent.set('child3', child3);
1029+
await Parse.Object.saveAll([child1, child2, child3, parent]);
1030+
1031+
const query = new Parse.Query('Container');
1032+
query.equalTo('objectId', parent.id);
1033+
query.includeAll();
1034+
1035+
const results = await query.find();
1036+
1037+
assert.equal(results.length, 1);
1038+
const parentAgain = results[0];
1039+
assert.equal(parentAgain.get('child1').get('foo'), 'bar');
1040+
assert.equal(parentAgain.get('child2').get('foo'), 'baz');
1041+
assert.equal(parentAgain.get('child3').get('foo'), 'bin');
1042+
});
1043+
1044+
it('can includeAll nested objects in .each', async () => {
1045+
const child1 = new TestObject({ foo: 'bar' });
1046+
const child2 = new TestObject({ foo: 'baz' });
1047+
const child3 = new TestObject({ foo: 'bin' });
1048+
const parent = new Parse.Object('Container');
1049+
parent.set('child1', child1);
1050+
parent.set('child2', child2);
1051+
parent.set('child3', child3);
1052+
await Parse.Object.saveAll([child1, child2, child3, parent]);
1053+
1054+
const query = new Parse.Query('Container');
1055+
query.equalTo('objectId', parent.id);
1056+
query.includeAll();
1057+
1058+
await query.each((obj) => {
1059+
assert.equal(obj.get('child1').get('foo'), 'bar');
1060+
assert.equal(obj.get('child2').get('foo'), 'baz');
1061+
assert.equal(obj.get('child3').get('foo'), 'bin');
1062+
});
1063+
});
1064+
10211065
it('can include nested objects via array', (done) => {
10221066
let child = new TestObject();
10231067
let parent = new Parse.Object('Container');

src/ParseQuery.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,11 @@ class ParseQuery {
345345
this._order = json.order.split(",");
346346
}
347347

348-
for (let key in json) if (json.hasOwnProperty(key)) {
349-
if (["where", "include", "keys", "limit", "skip", "order"].indexOf(key) === -1) {
350-
this._extraOptions[key] = json[key];
348+
for (let key in json) {
349+
if (json.hasOwnProperty(key)) {
350+
if (["where", "include", "keys", "limit", "skip", "order"].indexOf(key) === -1) {
351+
this._extraOptions[key] = json[key];
352+
}
351353
}
352354
}
353355

@@ -1313,6 +1315,11 @@ class ParseQuery {
13131315
/**
13141316
* Includes nested Parse.Objects for the provided key. You can use dot
13151317
* notation to specify which fields in the included object are also fetched.
1318+
*
1319+
* You can include all nested Parse.Objects by passing in '*'.
1320+
* Requires Parse Server 3.0.0+
1321+
* <pre>query.include('*');</pre>
1322+
*
13161323
* @param {...String|Array<String>} key The name(s) of the key(s) to include.
13171324
* @return {Parse.Query} Returns the query, so you can chain this call.
13181325
*/
@@ -1327,6 +1334,17 @@ class ParseQuery {
13271334
return this;
13281335
}
13291336

1337+
/**
1338+
* Includes all nested Parse.Objects.
1339+
*
1340+
* Requires Parse Server 3.0.0+
1341+
*
1342+
* @return {Parse.Query} Returns the query, so you can chain this call.
1343+
*/
1344+
includeAll(): ParseQuery {
1345+
return this.include('*');
1346+
}
1347+
13301348
/**
13311349
* Restricts the fields of the returned Parse.Objects to include only the
13321350
* provided keys. If this is called multiple times, then all of the keys

src/__tests__/ParseQuery-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,32 @@ describe('ParseQuery', () => {
899899
});
900900
});
901901

902+
it('can includeAll for pointers', () => {
903+
const q = new ParseQuery('Item');
904+
q.includeAll();
905+
const json = q.toJSON();
906+
expect(json).toEqual({
907+
where: {},
908+
include: '*',
909+
});
910+
const q2 = new ParseQuery('Item');
911+
q2.withJSON(json);
912+
expect(q2._include).toEqual(['*']);
913+
});
914+
915+
it('can use extraOptions', () => {
916+
const q = new ParseQuery('Item');
917+
q._extraOptions.randomOption = 'test';
918+
const json = q.toJSON();
919+
expect(json).toEqual({
920+
where: {},
921+
randomOption: 'test',
922+
});
923+
const q2 = new ParseQuery('Item');
924+
q2.withJSON(json);
925+
expect(q2._extraOptions.randomOption).toBe('test');
926+
});
927+
902928
it('can specify certain fields to send back', () => {
903929
var q = new ParseQuery('Item');
904930
q.select('size');
@@ -1300,6 +1326,7 @@ describe('ParseQuery', () => {
13001326
limit: 100,
13011327
order: 'objectId',
13021328
keys: 'size,name',
1329+
include: '*',
13031330
where: {
13041331
size: {
13051332
$in: ['small', 'medium']
@@ -1338,6 +1365,7 @@ describe('ParseQuery', () => {
13381365
);
13391366
q.equalTo('valid', true);
13401367
q.select('size', 'name');
1368+
q.includeAll();
13411369
var calls = 0;
13421370

13431371
q.each((o) => {

0 commit comments

Comments
 (0)