Skip to content

Instantly share code, notes, and snippets.

@orangeeli
Created December 25, 2015 23:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orangeeli/5995edf466c3de650319 to your computer and use it in GitHub Desktop.
Save orangeeli/5995edf466c3de650319 to your computer and use it in GitHub Desktop.
A small code snippet that shows how to return items from a relation since include is only for pointer columns (parse.com javascript SDK)
function get(req, res) {
var Foo,
query,
foos;
Foo = Parse.Object.extend("Foo", {}, {});
query = new Parse.Query(Foo);
foos = [];
query.
each(function(foo){
var bar = foo.relation("bar");
return bar.query().find().
then(function(bar){
// do stuff
// push the foos to an array to have them acessable later
foos.push(foo);
// just to return something successfully. The iteration will only continue if a promise is returned successfully
// https://parse.com/docs/js/api/classes/Parse.Query.html#methods_each
return Parse.Promise.as(foo);
}, cm.promiseHandleError);
}, function(error){
return Parse.Promise.error(error);
}).
then(function () {
res.json({foos: foos});
}, function(error){
res.status(500).json("Error retrieving list of foos.");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment