Skip to content

Instantly share code, notes, and snippets.

@matthewarkin
Last active August 29, 2015 14:06
Show Gist options
  • Save matthewarkin/935eca2670d9ad568d88 to your computer and use it in GitHub Desktop.
Save matthewarkin/935eca2670d9ad568d88 to your computer and use it in GitHub Desktop.
toObject sails
Model
.findOne(parentPk) //type app
.populate(relation, { //populate categories
where: where
})
.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
})
.populate('tags');
categoryQuery.exec(function (err, matchingCategories){
var temp = matchingRecord.toObject();
temp.categories=matchingCategories;
console.log("------temp Log--------")
console.log(temp); // good temp.categories includes tags
matchingRecord.categories = matchingCategories;
console.log("------App Log--------")
console.log(matchingRecord); //matchingRecord.categories doesn't include tags
console.log("------Categories Log------")
console.log(matchingRecord.categories); //outputs tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment