Repository navigation
change: remove deprecation from notNull for custom messages / enforce use of allowNull with this validator - #9549
Merged
Merged
Conversation
…lowNull usage with it
Alexsey
reviewed
Jun 17, 2018
| validator.notNull = function() { | ||
| throw new Error('Warning "notNull" validation has been deprecated in favor of Schema based "allowNull"'); | ||
| validator.notNull = function(val) { | ||
| return [null, undefined].indexOf(val) === -1; |
Contributor
There was a problem hiding this comment.
Since v5 targets NodeJS 6+ it's now possible to return [null, undefined].includes(val)
Contributor
Author
There was a problem hiding this comment.
Thanks, I just copied this code from old PR, will change
|
@sushantdhiman when those changes will be online with the latest npm varsion? |
Contributor
Author
|
Next beta release |
yocontra
reviewed
Jul 15, 2018
| } | ||
|
|
||
| if (attribute.allowNull !== false && _.get(attribute, 'validate.notNull')) { | ||
| throw new Error(`Invalid definition for "${this.name}.${name}", "notNull" validator is only allowed with "allowNull:false"`); |
Contributor
There was a problem hiding this comment.
This is a great change for developer UX 👍 @sushantdhiman
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…lowNull usage with it
Pull Request check-list
Please make sure to review and check all of these items:
npm run testornpm run test-DIALECTpass with this change (including linting)?Description of change
Fixes #1500
Sequelize can customize
allowNullerror messages withnotNullvalidator, but validator throw error when value is notnulldue to deprecation fornotNull.I have removed that deprecation, it was only introduced to enforce users to use
allowNullovernotNull, I have added some checks that will only allow use ofnotNullwithallowNull: false.So overall if users want to prevent null values they can as usual use
allowNull: false, but if they want to customize that error message, they can usenotNull.msg