jugglingdb
jugglingdb copied to clipboard
Why can't I set attribute directly on instance when in hooks?
I want to do something like:
var Passport = db.define('passport', {
password: String, // password hashed
})
Passport.validatesLengthOf('password', {min: 6});
Passport.afterValidate = function() {
this.password = Passport.hash(this.password)
}
But actually, I have to do
Passport.afterValidate = function(next, data) {
data.password = Passport.hash(data.password)
next()
}
This is not well documented, and it takes me quite a while to figure out what's going on.
I'm just curious, why not just allow people to set instance attribute directly, instead of passing data round and round?
Oh, wait, I cannot do the later, either, since data is not passed to afterHooks...