On the sequelize-agent I used the sequelize model hooks like .beforeSave. It looks like I am supposed to use the collection hooks now. I have a few questions regarding that:
How do I get access to the full dataset of the model being created/updated? In the context parameter for “Before Update”, I only see the changed fields in _patch and the model ID in the conditionTree. Is there any way like in actions for example to receive the full model and easily get the ID? Before saving for example I must retrieve related objects, validate fields and update relations.
There is no “save” hook, right? Its only “Update” OR “Create”?
Can I enable the sequel core beforeSave etc. hooks somehow?
Just to clarify: you have migrated your agent and it is now a nodejs agent instead of express-sequelize, right ?
to get the full model object being created/updated, the simplest way is to call a “list” with the filter provided in the context: const updatedProjectsNames = await hookContext.collection.list(hookContext.filter, ['name']);
yes, the save hooks has been replaced by update/create hooks. You’ll have to setup both if you want to achieve the exact same behaviour as a save hook.
No, the nodejs agent has a completely new codebase, the beforeSave cannot be re-enabled.But if you reuse the same method in the new update/create hooks, you should be able to reproduce the same behaviour with just a few changes.