Skip to content

Feature #4527 "skip" option for custom validators#4528

Merged
mickhansen merged 1 commit intosequelize:masterfrom
superclarkk:patch-1
Sep 17, 2015
Merged

Feature #4527 "skip" option for custom validators#4528
mickhansen merged 1 commit intosequelize:masterfrom
superclarkk:patch-1

Conversation

@superclarkk
Copy link
Copy Markdown
Contributor

Enable .validate(options.skip) to skip specific model/custom validators #4527
Return false to exit iteration early when using _.each and _.forIn , as per lodash docs

@mickhansen
Copy link
Copy Markdown
Contributor

Concerning BC: i don't think this constitutes a breaking change since i don't believe you would have model validators named the same as attributes.

/cc @janmeier

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the iteration supposed to be exited early though? skip might match the first field, should still validate all the other fields.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was exiting early with just "return", but the lodash docs state that it should be return false. I changed this line just so that it was consistent with my main changes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you absolutely sure about that? lodash docs says you have to explicitely return false.
If it's currently exiting the loop early with just return that would be a bug.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/lodash/lodash/blob/master/lodash.js#L3352 it tests for explicit false, return undefined would not break loop.

@superclarkk
Copy link
Copy Markdown
Contributor Author

@mickhansen If by "attributes" you mean fields (table columns), then you are correct. An error is thrown if a custom validator (model validator) and an attribute have the same name.

@mickhansen
Copy link
Copy Markdown
Contributor

@superclarkk i did mean model/table fields, thanks for confirming :)

mickhansen added a commit that referenced this pull request Sep 17, 2015
Feature #4527 "skip" option for custom validators
@mickhansen mickhansen merged commit cfd4da8 into sequelize:master Sep 17, 2015
mickhansen added a commit that referenced this pull request Sep 17, 2015
@mickhansen
Copy link
Copy Markdown
Contributor

Published in 3.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants