Sunday 15 July 2012

node.js - Cannot get Sequelize validation working -


I am trying to implement verification in my sequel model. The model is defined as follows:

  var model = sequelize.define ('model', {to: {type: dataTypes.STRING, allowNull: false, validate: {isEmail: True}}}   

Then I am trying to create an example and validate it:

  var m = Model.build (from: 'Obviously not an email'}} Var err = m.validate ();   

But if I do console.log (err) Code> {fct: [function]} defines only a custom variant that threw an exception result in an unrestricted exception

How do I use validate ?

v2.0.0 :

  var Sequelize = need ("sequelize") is required with the way to solve your problem, sequelize = new sequelize ("Sequelize_test", "root") var model = sequelize.define ('model', {to: {type: Sequelize.STRING, AllowNull: incorrect, valid: {isEmail: true}}} model. Sync () Validate (work () {Model.build ({fro M: "foo @ bar"}). Success (function (errors) {console.log (errors)})}}   

The following will be the result:

  {from: ['invalid email']}   

Side note: you valid -Call the call and can simply create it instead of the example:

  Model.sync (). Success (work () {model .create ({to: "foo @ Bar "}) .success (function () {console.log ('OK')} .error (function (errors) {console.log (errors)})})   

Error code as the previous code is very The only error object will be the snippet.

Greetings, SDPold.

No comments:

Post a Comment