modella/modella — pull request #26 by ramitos (2013-11-30 00:00:41+00:00)
Title: runs 'saving' events in series and validates on each (possible fix for #11)

There are two usages for this:

Object mutation on `save`
```js
var modella = require('./'),
User = modella('User');

User.validate(function(user) {
if(!user.username()) {
user.error('username', "is required");
}
});

User.on('saving', function(user, fn) {
setTimeout(function() {
user.username(null);
fn();
}, 200);
});

User
.attr('_id')
.attr('username', { required: true });

var user = new User({
username: 'john'
});

user.save(function(err){
console.log(err.message) //=> validation failed
console.log(user.errors[0].attr) //=> username
console.log(user.errors[0].message) //=> is required
});
```

Asynchronous validation
```js
var modella = require('./'),
User = modella('User');

User.on('saving', function(user, fn) {
setTimeout(function() {
if(!user.username()) {
user.error('username', "is required");
}
fn();
}, 200)
});

User
.attr('_id')
.attr('username', { required: true });

var user = new User();

user.save(function(err){
console.log(err.message) //=> validation failed
console.log(user.errors[0].message) //=> not valid
});
```