Last active
August 29, 2015 14:06
-
-
Save matthewarkin/935eca2670d9ad568d88 to your computer and use it in GitHub Desktop.
toObject sails
This file contains hidden or 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
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