upsert method doesn't trigger any hooks for mysql adapter
- Lenguaje dominante
- JavaScript
- Estrellas
- 2k
- Forks
- 238
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
Hi,
I found that the upsert method won't trigger any hook if the adapter support updateOrCreate method (mysql in my case). I debugged and found the reason in below code:
https://github.com/1602/jugglingdb/blob/04adcdbd13c9ad9ddb0b9bb0a18e4620c17f56fc/lib/model.js#L336
```javascript
if (this.schema.adapter.updateOrCreate) {
const inst = new Model(data);
this.schema.callAdapter('updateOrCreate', Model.modelName, stripUndefined(inst.toObject(true)), (err, data) => {
if (data) {
return inst.reload(callback);
}
callback(err, null);
});
} else {
...
}
```
I think it should trigger *save/update* hooks like other methods,
If you need, i can create a PR for it,
Thank you very much for a nice job!
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
The issue is in lib/model.js around line 336, where the upsert method uses adapter.updateOrCreate. Look at the save/update hooks in the same file to see how they are triggered elsewhere. Test with the MySQL adapter to confirm hooks are missing, then modify the updateOrCreate path to call the appropriate hooks. Check test files for hook-related tests to ensure the fix works.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, mysql
- Á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