Hooks
Hooks allow us to perform actions at different points throughout the life cycle of a model. For example, we could do something before an item is updated or after an item is created.
Sequelize supports many types of hooks. Full list in documentation
Example: normalize tags using beforeCreate
If we want all of our tags to be stored in all caps we could use a beforeCreate hook. This way if someone adds a tag Taco
it will be stored as TACO
and all of our tags will be the same.
We can use beforeCreate hook to automatically hash a users password before it is created (AKA before the data is inserted into the database).
Last updated