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

Commit 05a8ac72 by Bart Nagel

Put model errors alongside field errors by validation name

Instead of a hash called __model with the model validation errors, the
model validation errors are now alongside the field validation keys of
the hash, named after the validation's key in the validate array. To be
as consistent as possible, the value is an array even though it will
only ever have one member. The structure is set to change in 2.0.

Example: where there was a model validation set up like

	validate: {
		xnor: function() {
			if (this.field1 === null) === (this.field2 === null) {
				throw new Error('require both or neither')
			}
		}
	}

and field1 and field2 have some validations, validate() might return
something like

	{
		field1: [
			'must be an email address',
			'email address must be @example.com'
		],
		xnor: ['require both or neither']
	}
1 parent 47591d75
Showing with 2 additions and 5 deletions
......@@ -276,10 +276,7 @@ module.exports = (function() {
try {
validator.apply(self)
} catch (err) {
if (!failures.hasOwnProperty('__model')) {
failures.__model = []
}
failures.__model.push(err.message)
failures[validatorType] = [err.message] // TODO: data structure needs to change for 2.0
}
})
......
......@@ -330,7 +330,7 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
var failingFoo = Foo.build({ field1: null, field2: null })
, errors = failingFoo.validate()
expect(errors).not.toBeNull()
expect(errors).toEqual({ '__model': ['xnor failed'] })
expect(errors).toEqual({ 'xnor': ['xnor failed'] })
var successfulFoo = Foo.build({ field1: 33, field2: null })
expect(successfulFoo.validate()).toBeNull()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!