Skip to content

Commit f1b0083

Browse files
authored
Support include('*') Query (#4947)
1 parent 35da17b commit f1b0083

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

spec/ParseQuery.spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3474,6 +3474,50 @@ describe('Parse.Query testing', () => {
34743474
});
34753475
});
34763476

3477+
it('include with *', async () => {
3478+
const child1 = new TestObject({ foo: 'bar', name: 'ac' });
3479+
const child2 = new TestObject({ foo: 'baz', name: 'flo' });
3480+
const child3 = new TestObject({ foo: 'bad', name: 'mo' });
3481+
const parent = new Container({ child1, child2, child3 });
3482+
await Parse.Object.saveAll([parent, child1, child2, child3]);
3483+
const options = Object.assign({}, masterKeyOptions, {
3484+
body: {
3485+
where: { objectId: parent.id },
3486+
include: '*',
3487+
}
3488+
});
3489+
const resp = await rp.get(Parse.serverURL + "/classes/Container", options);
3490+
const result = resp.results[0];
3491+
equal(result.child1.foo, 'bar');
3492+
equal(result.child2.foo, 'baz');
3493+
equal(result.child3.foo, 'bad');
3494+
equal(result.child1.name, 'ac');
3495+
equal(result.child2.name, 'flo');
3496+
equal(result.child3.name, 'mo');
3497+
});
3498+
3499+
it('include with * overrides', async () => {
3500+
const child1 = new TestObject({ foo: 'bar', name: 'ac' });
3501+
const child2 = new TestObject({ foo: 'baz', name: 'flo' });
3502+
const child3 = new TestObject({ foo: 'bad', name: 'mo' });
3503+
const parent = new Container({ child1, child2, child3 });
3504+
await Parse.Object.saveAll([parent, child1, child2, child3]);
3505+
const options = Object.assign({}, masterKeyOptions, {
3506+
body: {
3507+
where: { objectId: parent.id },
3508+
include: 'child2,*',
3509+
}
3510+
});
3511+
const resp = await rp.get(Parse.serverURL + "/classes/Container", options);
3512+
const result = resp.results[0];
3513+
equal(result.child1.foo, 'bar');
3514+
equal(result.child2.foo, 'baz');
3515+
equal(result.child3.foo, 'bad');
3516+
equal(result.child1.name, 'ac');
3517+
equal(result.child2.name, 'flo');
3518+
equal(result.child3.name, 'mo');
3519+
});
3520+
34773521
it('includeAll', (done) => {
34783522
const child1 = new TestObject({ foo: 'bar', name: 'ac' });
34793523
const child2 = new TestObject({ foo: 'baz', name: 'flo' });

src/RestQuery.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ function RestQuery(config, auth, className, restWhere = {}, restOptions = {}, cl
114114
break;
115115
case 'include': {
116116
const paths = restOptions.include.split(',');
117+
if (paths.includes('*')) {
118+
this.includeAll = true;
119+
break;
120+
}
117121
// Load the existing includes (from keys)
118122
const pathSet = paths.reduce((memo, path) => {
119123
// Split each paths on . (a.b.c -> [a,b,c])

0 commit comments

Comments
 (0)