这是我的User
模型定义
options: {
tableName: 'cushbu_users',
hooks:{},
timestamps:false,
/*--field names and validation rules --*/
email:{
type:Sequelize.STRING,
validate:{
notEmpty:true
}
},
first_name:{
type:Sequelize.STRING,
validate:{
notEmpty:true
}
}
}
如何在 Controller 中获取模型验证错误消息
我尝试过这些
User.validate().success(function () {
console.log('ok');
}).error(function (error) {
console.log(error);
})
但是我收到以下错误user.validate not function
最佳答案
您应该从即时对象调用此方法,而不是像这样的 Sequelize 模型:
User.create({
name: "test"
email: "test"
password: "test"
}).then(function(user){
// validate
errors = user.validate();
});
关于node.js - nodejs Sequelize orm model.validation 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44544918/