1602 / jugglingdb

Multi-database ORM for nodejs: redis, mongodb, mysql, sqlite3, postgresql, arango, in-memory...
http://1602.github.io/jugglingdb/
2.05k stars 241 forks source link

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

Open ktmud opened 10 years ago

ktmud commented 10 years ago

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 commented 10 years ago

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