1602 / 1602/jugglingdb

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

Offen
#385 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
2k
Forks
238
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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?

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, nodejs
Bereich
backend, databases
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.