Why can't I set attribute directly on instance when in hooks?
- Lingua principale
- JavaScript
- Stelle
- 2k
- Fork
- 238
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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?
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Look at the ORM's hook implementation, likely in lib/hooks.js or similar, to understand how afterValidate receives data. Examine the instance context and data parameter handling. Check existing tests for hooks to see the expected behavior. The fix involves modifying the hook execution to allow direct instance attribute assignment or improving documentation.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, nodejs
- Ambito
- backend, databases
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100