Mixin Hooks
Hooks are function that are called before and after (bulk-) creation/updating/deletion and validation. Hooks can be added to you models in three ways:
- By specifying them as options in
- By calling
hook()
with a string and your hook handler function
See:
Add a hook to the model
Params:
Aliases: hook
removeHook(hookType, name)
Remove hook from the model
Params:
Name | Type | Description |
---|---|---|
hookType | String | |
name | String |
hasHook(hookType)
Check whether the mode has any hooks of this type
Params:
Name | Type | Description |
---|---|---|
hookType | String |
Aliases: hasHooks
beforeValidate(name, fn)
A hook that is run before validation
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with instance, options |
afterValidate(name, fn)
A hook that is run after validation
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with instance, options |
validationFailed(name, fn)
A hook that is run when validation fails
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with instance, options, error. Error is the SequelizeValidationError. If the callback throws an error, it will replace the original validation error. |
beforeCreate(name, fn)
A hook that is run before creating a single instance
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with attributes, options |
afterCreate(name, fn)
A hook that is run after creating a single instance
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with attributes, options |
beforeDestroy(name, fn)
A hook that is run before destroying a single instance
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with instance, options |
Aliases: beforeDelete
afterDestroy(name, fn)
A hook that is run after destroying a single instance
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with instance, options |
Aliases: afterDelete
beforeRestore(name, fn)
A hook that is run before restoring a single instance
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with instance, options |
afterRestore(name, fn)
A hook that is run after restoring a single instance
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with instance, options |
beforeUpdate(name, fn)
A hook that is run before updating a single instance
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with instance, options |
A hook that is run after updating a single instance
Params:
beforeBulkCreate(name, fn)
A hook that is run before creating instances in bulk
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with instances, options |
afterBulkCreate(name, fn)
A hook that is run after creating instances in bulk
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with instances, options |
beforeBulkDestroy(name, fn)
A hook that is run before destroying instances in bulk
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options |
Aliases: beforeBulkDelete
afterBulkDestroy(name, fn)
A hook that is run after destroying instances in bulk
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options |
Aliases: afterBulkDelete
beforeBulkRestore(name, fn)
A hook that is run before restoring instances in bulk
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options |
afterBulkRestore(name, fn)
A hook that is run after restoring instances in bulk
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options |
beforeBulkUpdate(name, fn)
A hook that is run before updating instances in bulk
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options |
afterBulkUpdate(name, fn)
A hook that is run after updating instances in bulk
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options |
beforeFind(name, fn)
A hook that is run before a find (select) query
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options |
beforeFindAfterExpandIncludeAll(name, fn)
A hook that is run before a find (select) query, after any { include: {all: …} } options are expanded
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options |
beforeFindAfterOptions(name, fn)
A hook that is run before a find (select) query, after all option parsing is complete
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options |
afterFind(name, fn)
A hook that is run after a find (select) query
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with instance(s), options |
A hook that is run before a count query
Params:
beforeDefine(name, fn)
A hook that is run before a define call
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with attributes, options |
afterDefine(name, fn)
A hook that is run after a define call
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with factory |
beforeInit(name, fn)
A hook that is run before Sequelize() call
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with config, options |
afterInit(name, fn)
A hook that is run after Sequelize() call
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with sequelize |
beforeConnect(name, fn)
A hook that is run before a connection is created
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with config passed to connection |
afterConnect(name, fn)
A hook that is run after a connection is created
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with the connection object and thye config passed to connection |
beforeSync(name, fn)
A hook that is run before Model.sync call
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options passed to Model.sync |
beforeConnect(name, fn)
A hook that is run before a connection is created
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with config passed to connection |
beforeSync(name, fn)
A hook that is run before Model.sync call
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options passed to Model.sync |
afterSync(name, fn)
A hook that is run after Model.sync call
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options passed to Model.sync |
beforeBulkSync(name, fn)
A hook that is run before sequelize.sync call
Params:
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options passed to sequelize.sync |
afterBulkSync
A hook that is run after sequelize.sync call
Name | Type | Description |
---|---|---|
name | String | |
fn | Function | A callback function that is called with options passed to sequelize.sync |
This document is automatically generated based on source code comments. Please do not edit it directly, as your changes will be ignored. Please write on , open an issue or a create a pull request if you feel something can be improved. For help on how to write source code documentation see JSDoc and