Here's how to solve your problem with Sequelize v2.0.0 :
var Sequelize = require("sequelize") , sequelize = new Sequelize("sequelize_test", "root") var Model = sequelize.define('Model', { from: { type: Sequelize.STRING, allowNull: false, validate: { isEmail: true } } }) Model.sync().success(function() { Model.build({ from: "foo@bar" }).validate().success(function(errors) { console.log(errors) }) })
This will lead to:
{ from: [ 'Invalid email' ] }
Note: you can also skip validate -call and just instantiate instead:
Model.sync().success(function() { Model .create({ from: "foo@bar" }) .success(function() { console.log('ok') }) .error(function(errors) { console.log(errors) }) })
The error method will receive the same error object as in the previous code fragment.
Hi sdepold.
sdepold
source share