Created
December 25, 2015 23:02
A small code snippet that shows how to return items from a relation since include is only for pointer columns (parse.com javascript SDK)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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