Validator does not run if the field is not provided.
See original GitHub issueAssume a very simple model:
var user = sequelize.define('user',
{
email: {
type: DataTypes.STRING,
validate: {
isEmail: {
msg: 'Email must be a valid email address'
},
notEmpty: {
msg: 'Email is a required field'
}
}
}
})
If I do user.create({})
the validation rules in the email does not run.
I am wondering why this is? The only thing I can see is, I am missing the schema validator allowNull: true
however, this does not return an user friendly error message.
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
javascript - Joi .custom() validator does not get executed on a ...
Now my problem is, that the custom validator does not get executed when I send in: { firstField: "test", }. But I want...
Read more >Content validation | Looker - Google Cloud
The Content Validator searches your LookML for model, Explore, and field names referenced in your Looker content.
Read more >Restrict data input by using validation rules - Microsoft Support
Validations rules help you check data as it is added to your Access desktop database which improves accuracy and consistency of data entry....
Read more >Validate - Go Packages
The field under validation must be present and not empty only if any of the other specified fields are present. For strings ensures...
Read more >Validators — WTForms Documentation (3.0.x) - Read the Docs
In-line validators are good for validating special cases, but are not easily reusable. If, in the example above, the name field were to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The validations won’t run, since the field is empty and this is a valid entry as long as you do not use allowNull: false (allowNull: true is the default value). So using allowNull: false is fixing your issue.
If
allowNull
not set, all regular validations will not work for null attributes. ButallowNull
will addNOT NULL
constraint on table schema which I don’t need. So how can I do builtinAttrValidate likenotNull
ifallowNull
is not set?