我有一张看起来像这样的表
var competence_develop_comp = sequelize.define('competence_develop_comp', {
competence_id: {
type: DataTypes.INTEGER,
primaryKey: true
},
level_difference: DataTypes.INTEGER,
division_id: DataTypes.INTEGER,
timestamp : DataTypes.DATE
}, {
freezeTableName: true,
instanceMethods: {
retrieveByDivision: function (adminDivisions, onSuccess, onError) {
competence_develop_comp.sum('level_difference',{
include: [{model: Competence}],
where: {division_id: {$in: adminDivisions}},
order: 'timestamp DESC,level_difference DESC',
GROUP: 'competence_id',
limit: 10
}).ok(onSuccess).error(onError);
},
retrieveByDivisionId: function (division_id, onSuccess, onError) {
competence_develop_comp.findAll({
include: [{model: Competence}],
where: {division_id: division_id},
order: 'timestamp DESC, level_difference DESC',
limit: 10
}).ok(onSuccess).error(onError);
}
}
}
);
正如您所见,我已尝试使用以下内容sum
字段level_difference
:
competence_develop_comp.sum('level_difference',{
include: [{model: Competence}],
where: {division_id: {$in: adminDivisions}},
order: 'timestamp DESC,level_difference DESC',
GROUP: 'competence_id',
limit: 10
}).ok(onSuccess).error(onError);
然而,当我这样做时,我收到以下错误:
TypeError: Cannot call method 'map' of undefined
对于每个结果,我需要level_difference
那么我将如何使用sequelize