jugglingdb icon indicating copy to clipboard operation
jugglingdb copied to clipboard

Why can't I set attribute directly on instance when in hooks?

Open ktmud opened this issue 11 years ago • 1 comments

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?

ktmud avatar Mar 02 '14 09:03 ktmud

Oh, wait, I cannot do the later, either, since data is not passed to afterHooks...

ktmud avatar Mar 02 '14 09:03 ktmud