1602 / 1602/jugglingdb

upsert method doesn't trigger any hooks for mysql adapter

Open
#461 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2k
Forks
238
PR merge metrics
No merged PRs in 30d

Description

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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.