1602 / 1602/jugglingdb

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

Abierto
#385 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
2k
Forks
238
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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?

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, nodejs
Área
backend, databases
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.