Sequelize获取列总和-TypeError:无法读取未定义的属性“ includes”

时间:2019-08-18 19:28:06

标签: sequelize.js sequelize-typescript

我正在为项目使用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)

1 个答案:

答案 0 :(得分:0)

您不能像这样使用AgencyEventReportTable.sum,请尝试以下操作:

AgencyEventReportTable.findAll({
        attributes: [
            'agency_id',
            'user_id'
            [
                sequelize.fn('sum', sequelize.col('total_selled'))
                'total'
            ]

        ],
        group: ['user_id', 'agency_id']
})