-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
option for ignore validation on fields with 'allowNull=true' #270
Comments
This is the same as #118, and it's not clear why that one is closed. I'd like to see this implemented, but I don't think it should even be an option. If allowNull is true, clearly you want to allow null. If it's not null, only then should the other validations happen. As for the other issue I commented on tonight, I'll offer a small donation as bounty if this is addressed soon. |
Agree, this should be implemented. I think we can safely infer that if a field allows null it should not be validated if it contains a null value. |
So, for instance, if a string field has allowNull: true, but also validate: len: 1, an empty string "" should fail, a string "string" should pass, and null should pass. |
Implemented in #601 |
@tremby and @janmeier Hello and sorry to bring this up after so many years, but I would like to point out that this should be an opt-out option instead of a forced behaviour. @tremby said: "I don't think it should even be an option. If allowNull is true, clearly you want to allow null." This is being a problem for me, because I want to allow null depending on other fields: myField: {
validate: {
custom(value) {
if (value === null && !foobar(this.otherField1, this.otherField2)) {
throw new Error("myField can't be null when otherField1 and otherField2 satisfy property X");
}
}
}
} But with the changes made in #601, if I do This should be an option (that comes enabled, of course), so I can disable it for What do you think? Thanks a lot! |
I hadn't considered a use case like that. But I am going to bow out of discussion -- I haven't used Sequelize in years. |
Would be nice to have an option to ignore the validation settings if the field value is null with the allowNull parameter set.
Another way would be come up with custom validation methods (for example 'allowNullOrIsEmail') but that would mean that we need access to the other validation functions (to reuse em).
The text was updated successfully, but these errors were encountered: