我正在为项目使用NodeJ,Expressjs和Sequelize。
我的代码是:
static report() {
return AgencyEventReportTable.findAll({
attributes: [
'agency_id',
'user_id'
[
AgencyEventReportTable.sum('total_selled'),
'total'
]
],
group: ['user_id', 'agency_id']
})
}
在Sequelize中使用Model.sum时出现的错误:
Unhandled rejection TypeError: Cannot read property 'includes' of undefined
at attributes.map.attr (/home/node-server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1412:22)
at MySQLQueryGenerator.selectQuery (/home/node-server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1156:28)
at QueryInterface.select (/home/node-server/node_modules/sequelize/lib/query-interface.js:1119:27)
答案 0 :(得分:0)
您不能像这样使用AgencyEventReportTable.sum
,请尝试以下操作:
AgencyEventReportTable.findAll({
attributes: [
'agency_id',
'user_id'
[
sequelize.fn('sum', sequelize.col('total_selled'))
'total'
]
],
group: ['user_id', 'agency_id']
})