Skip to content

Instantly share code, notes, and snippets.

@matthewarkin
Last active August 29, 2015 14:05
Show Gist options
  • Save matthewarkin/007a9ece539d2ccdb040 to your computer and use it in GitHub Desktop.
Save matthewarkin/007a9ece539d2ccdb040 to your computer and use it in GitHub Desktop.
attempting deep population
var query = Model.findOne(pk);
query = actionUtil.populateEach(query, req);
query.exec(function found(err, matchingRecord) {
//get list of all category id
var categoryModel = req._sails.models['category'];
var categoryIds = _.flatten(matchingRecord.categories,"id");
var categoryQuery = categoryModel.find({
id:categoryIds
});
categoryQuery = actionUtil.populateEach(categoryQuery, {param: req.param, options: {associations: [categoryModel.associations[1]], populate:true}});
categoryQuery.exec(function (err, matchingCategories){
matchingRecord.categories = matchingCategories;
console.log(matchingRecord.categories); //good
console.log(matchingRecord); //bad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment