我在sequelize上遇到了一个非常奇怪的问题,当我try 调用函数findAll时,它工作得很好(create和destroy也是如此),但当我try 调用函数"findById"时,它抛出"findById不是函数"(FindOne也是如此).
//works fine
var gammes = models.gamme.findAll().then(function(gammes) {
res.render('admin/gammes/gestion_gamme',{
layout: 'admin/layouts/structure' ,
gammes : gammes,
js: "gammes"
});
});
// throws models.gamme.findById is not a function
models.gamme.findById(req.params.id).then(function(gamme) {
gamme.update({
nom: req.body.nom
}).then(function () {
res.redirect("/gammes");
})
});
加姆.js模型
module.exports = function (sequelize, DataTypes) {
"use strict";
var gamme = sequelize.define('gamme', {
id_gamme: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true
},
nom: {
type: DataTypes.STRING,
allowNull: false
}
}, {
classMethods: {},
timestamps: false
});
return gamme;
};