我在 Node JS 中使用 Sequelize 作为 ORM。在有两个禁忌。事件和评论。我这样联想:事件有很多评论。现在我想检索所有事件并计算每个事件的评论数。 现在我这样做:
db.Event.findAndCountAll({limit: limit,offset: offset, include: [ db.Comment], order: 'date DESC'}).
然后下一个返回
JSON.stringify(result.rows).
如何只用一个查询返回评论数。
请帮助我。
提前致谢
最佳答案
您将返回的“结果”是传递给成功回调函数的结果,对吗?
db.Event.findAndCountAll(...).success(
function(result) { // this guy
console.log(result.count) //this logs the count
}
)
可以使用result.count来获取值
关于javascript - Node JS Sequelize如何统计关联数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19348584/