How can I validate model before creating it. I know "create" validates model automatically.
But what if I have to validate 2 models and then if both are valid - create them. Otherwise to throw an error. Something like:
models.creditCard({
name:'test'
}).validate(function (err, data) {
if (! err) {
models.creditCard.create({
name: 'test'
}, function (err, data) {
}l
}
})
Thanks
Found solution, thanks :)
var creditcard = models.creditCard({
name:'test'
});
creditcard.isValid(function(valid) {
if (! valid) {
console.log(creditcard.errors);
}
});
@crandmck is this covered by our docs, either Confluence or API docs?
We have some doc on validation, but it really needs improvement. See #693.
You guys need to update one of the sample codes with validation... It is NOT clear where to add them.
Most helpful comment
Found solution, thanks :)