Skip to content

Support includeAll Query #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions integration/test/ParseQueryTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
21 changes: 18 additions & 3 deletions src/ParseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}

Expand Down Expand Up @@ -1313,6 +1315,10 @@ 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.
*
* If you want to include all nested Parse.Objects pass in '*'
* <pre>query.include('*');</pre>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we need to put a version number here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which version? 2.1.0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean server version?

Copy link
Member Author

@dplewis dplewis Aug 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea mate which version is, I can try to backtrack

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok ok, so basically it already works if you pass include All in the rest SDK.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is correct. Basically this won't work until the next release unless I re-add includeAll to this SDK

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let’s just use the * notation then we’ll perhaps be able to expand on with reg ex etc...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How best can we update the guides simultaneously with the API docs

*
* @param {...String|Array<String>} key The name(s) of the key(s) to include.
* @return {Parse.Query} Returns the query, so you can chain this call.
*/
Expand All @@ -1327,6 +1333,15 @@ class ParseQuery {
return this;
}

/**
* Includes all nested Parse.Objects.
*
* @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
Expand Down
28 changes: 28 additions & 0 deletions src/__tests__/ParseQuery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -1300,6 +1326,7 @@ describe('ParseQuery', () => {
limit: 100,
order: 'objectId',
keys: 'size,name',
include: '*',
where: {
size: {
$in: ['small', 'medium']
Expand Down Expand Up @@ -1338,6 +1365,7 @@ describe('ParseQuery', () => {
);
q.equalTo('valid', true);
q.select('size', 'name');
q.includeAll();
var calls = 0;

q.each((o) => {
Expand Down