yomexzo
yomexzo

Reputation: 685

How can I validate a record only without saving in nodejs | sailsjs | waterline

I seek something of this nature

//validation rules in model "User"
attributes: {
    age: {
        required: true,
        type: 'numeric'
    }
},    

//now in controller, i want to be able to do this
Recipe.validate({age: 'An invalid age because it is a string. I except a validation error as response'});

Problem is, it doesn't work.. it complains about beforeValidate not being available, e.t.c

Upvotes: 2

Views: 776

Answers (1)

sgress454
sgress454

Reputation: 24948

You need to pass a callback into .validate:

Recipe.validate({age: 'blah'}, function(err){
  if (err && err.invalidAttributes) {
    console.log(err.invalidAttributes); 
  } else {
    // model is valid
  }
});

Upvotes: 2

Related Questions