Coming from the rails word, I kind of miss the reload method.
I have noticed the following instructions in the documentation:
// If you need to refresh the same instance you can do this:
person.$query().then(reFetchedPerson => {
// Note that `person` did not get modified by the fetch.
person.$set(reFetchedPerson);
});
But It has proven to be cumbersome in practice. We have been writing the following plugin to make things easier:
function utils(Model) {
return class extends Model {
// Close to https://apidock.com/rails/ActiveRecord/Persistence/reload
async reload() {
const reFetched = await this.$query()
this.$set(reFetched)
}
}
}
export default utils
You could be interested in moving this helper into the core of the lib (I'm not sure about it), at least I wanted to give some feedback about my experience using objection.js.
IMO this shouldn't be a part in core, since there are so much this kind of small helpers that some people finds useful, that all of them cannot be added. Also we don't want to pollute namespace of base model, so method name would be $reload() I think.
I believe that its best to keep objection's base model really clean and let all the users define themselves these small helpers to their own base classes or to implement them as plugins.
I agree with the previous dude.
Most helpful comment
IMO this shouldn't be a part in core, since there are so much this kind of small helpers that some people finds useful, that all of them cannot be added. Also we don't want to pollute namespace of base model, so method name would be $reload() I think.
I believe that its best to keep objection's base model really clean and let all the users define themselves these small helpers to their own base classes or to implement them as plugins.