不要怂,就是干,撸起袖子干!

Commit 39c0b628 by Bart Nagel

Throw an error on model validator with same name as field

Plus a test for that
1 parent c8c6687e
Showing with 16 additions and 0 deletions
...@@ -23,6 +23,8 @@ module.exports = (function() { ...@@ -23,6 +23,8 @@ module.exports = (function() {
// error check options // error check options
Utils._.each(options.validate, function(validator, validatorType) { Utils._.each(options.validate, function(validator, validatorType) {
if (Utils._.contains(Utils._.keys(attributes), validatorType))
throw new Error("A model validator function must not have the same name as a field. Model: " + name + ", field/validation name: " + validatorType)
if (!Utils._.isFunction(validator)) if (!Utils._.isFunction(validator))
throw new Error("Members of the validate option must be functions. Model: " + name + ", error with validate member " + validatorType) throw new Error("Members of the validate option must be functions. Model: " + name + ", error with validate member " + validatorType)
}) })
......
...@@ -84,6 +84,20 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -84,6 +84,20 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) })
}.bind(this), 'Members of the validate option must be functions. Model: Foo, error with validate member notFunction') }.bind(this), 'Members of the validate option must be functions. Model: Foo, error with validate member notFunction')
}) })
it('throws an error if a custom model-wide validation has the same name as a field', function() {
Helpers.assertException(function() {
this.sequelize.define('Foo', {
field: {
type: Sequelize.INTEGER
}
}, {
validate: {
field: function() {}
}
})
}.bind(this), 'A model validator function must not have the same name as a field. Model: Foo, field/validation name: field')
})
}) })
describe('build', function() { describe('build', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!