Skip to content
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
40 changes: 40 additions & 0 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2393,4 +2393,44 @@ describe('Parse.Query testing', () => {
done();
});
});

it('include for specific object', function(done){
var child = new Parse.Object('Child');
var parent = new Parse.Object('Parent');
child.set('foo', 'bar');
parent.set('child', child);
Parse.Object.saveAll([child, parent], function(response){
var savedParent = response[1];
var parentQuery = new Parse.Query('Parent');
parentQuery.include('child');
parentQuery.get(savedParent.id, {
success: function(parentObj) {
var childPointer = parentObj.get('child');
ok(childPointer);
equal(childPointer.get('foo'), 'bar');
done();
}
});
});
});

it('select keys for specific object', function(done){
var Foobar = new Parse.Object('Foobar');
Foobar.set('foo', 'bar');
Foobar.set('fizz', 'buzz');
Foobar.save({
success: function(savedFoobar){
var foobarQuery = new Parse.Query('Foobar');
foobarQuery.select('fizz');
foobarQuery.get(savedFoobar.id,{
success: function(foobarObj){
equal(foobarObj.get('fizz'), 'buzz');
equal(foobarObj.get('foo'), undefined);
done();
}
});
}
})
});

});
19 changes: 18 additions & 1 deletion src/Routers/ClassesRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,24 @@ export class ClassesRouter extends PromiseRouter {

// Returns a promise for a {response} object.
handleGet(req) {
return rest.find(req.config, req.auth, req.params.className, {objectId: req.params.objectId})
let body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
let options = {};
let allowConstraints = ['keys', 'include'];
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move that up as a const ALLOWED_GET_QUERY_KEYS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


for (let key of Object.keys(body)) {
if (allowConstraints.indexOf(key) === -1) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Improper encode of parameter');
}
}

if (typeof body.keys == 'string') {
options.keys = body.keys;
}
if (body.include) {
options.include = String(body.include);
}

return rest.find(req.config, req.auth, req.params.className, {objectId: req.params.objectId}, options)
.then((response) => {
if (!response.results || response.results.length == 0) {
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.');
Expand Down