i have this code:
exports.calculate = function(req, res, next) {
statistics.commented_quizes = 0;
statistics.no_commented = 0;
Promise.all([
models.Quiz.count(),
models.Comment.count(),
models.Quiz.findAll({
include: [{
model: models.Comment
}]
})
]).then(function(results) { // `results` is an array of [quizes, comments, all]
statistics.quizes = results[0];
statistics.comments = results[1];
statistics.average_comments = (statistics.comments / statistics.quizes).toFixed(2);
for (index in results[2]) {
if (results[2][index].Comment.length) {
statistics.commented_quizes++;
} else {
statistics.no_commented++;
}
}
}).then(next, next);
};
This code cannot read length property of an undefined, in this case 'Comment'.
What is wrong? I tried to remove the property, but the results don't work properly, so i need to identify the bug, but i don't get it.
Thanks in advance!