instance.save not promisified (vs Model.create which is)
mrfelton opened this issue · 6 comments
The following code does not return a promise:
const instance = new Model({key: 'val'})
return instance.save()
Whilst the following does:
return Model.create({key: 'val'})
This is different from other connectors in which all DAO methods return a promise if a callback is not supplied.
Calling .save()
on a model instance should return a promise for a consistent DX.
I've noticed if you are debugging and you step into .save()
with a remote
connector you go to persisted-model.js
, but if you use memory
or another connector you go into dao.js
.
In dao.js
there is this line:
cb = cb || utils.createPromiseCallback();
But in persisted-model.js
the equivalent is:
callback = callback || function() {};
Oddly, I thought this was fixed: #39
The workaround seems to be:
promisify(instance.save.bind(instance))();
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I still think this is important and shouldn't be closed.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS
file at the top-level of this repository.
This should be reopened IMHO, it could lead to very subtle errors and documentation is not clear about that.