Hey,
is there any way to access new values in the $afterUpdate hook? I'm trying to integrate S3 with objection by mapping a string column to S3 keys and back.
Thanks!
Doesn't this.someProperty work?
Thanks for your fast reply. I tried that, however thisseems to refer to the patch/update object only. I think I found some evidence in this post:
https://github.com/Vincit/objection.js/issues/185
Which database are you using? On postgres you can chain returning('theColumYouNeed')
We are running postgres yes. We use .returning("*") in order to get everything back as needed. Yet, this does not seem to be available within $afterUpdate already.
For my specific usecase, I might also be able to use $parseDatabaseJson, yet it seems they don't support Promises yet, do they?
What I want to do is expose a unified API for file storage on models, e.g. models can be written by writing .insert({name: "foo", file: <File/Multipart>}). Behind the scenes, I would convert the contents of file and upload them to AWS S3. In the actual column itself, only the key should reside. When reading the model, I want to parse the key, and instead of {file: "someKey"}, I would like to return a complex object, similar to
Maybe something like this would work?
class Person extends Model {
query(...args) {
return super.query(...args).runAfter(async (result, builder) => {
if (builder.isInsert() || builder.isUpdate()) {
// Do the magic with `result`. It should contain the `returning` stuff.
}
return result;
});
}
}
Thanks for the suggestion. We now, solved it by using parseDatabaseJson and formatDatabaseJson to transform the values, and hooks to upload the files to S3.
Encountered the same issue. Surprised that this in the $afterUpdate hook only contains the updated fields even though returning('*') is used in the patch query.
This makes no sense to me when running patch via an instance method. Why is this only referring to the modified fields? This makes $afterUpdate virtually useless...
Most helpful comment
Encountered the same issue. Surprised that
thisin the$afterUpdatehook only contains the updated fields even thoughreturning('*')is used in the patch query.