Mixin Hooks

    View code

    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)

    View code

    Remove hook from the model

    Params:

    NameTypeDescription
    hookTypeString
    nameString

    hasHook(hookType)

    Check whether the mode has any hooks of this type

    Params:

    NameTypeDescription
    hookTypeString

    Aliases: hasHooks


    beforeValidate(name, fn)

    View code

    A hook that is run before validation

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with instance, options

    afterValidate(name, fn)

    A hook that is run after validation

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with instance, options

    validationFailed(name, fn)

    View code

    A hook that is run when validation fails

    Params:

    NameTypeDescription
    nameString
    fnFunctionA 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:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with attributes, options

    afterCreate(name, fn)

    View code

    A hook that is run after creating a single instance

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with attributes, options

    beforeDestroy(name, fn)

    A hook that is run before destroying a single instance

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with instance, options

    Aliases: beforeDelete


    afterDestroy(name, fn)

    View code

    A hook that is run after destroying a single instance

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with instance, options

    Aliases: afterDelete


    beforeRestore(name, fn)

    A hook that is run before restoring a single instance

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with instance, options

    afterRestore(name, fn)

    View code

    A hook that is run after restoring a single instance

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with instance, options

    beforeUpdate(name, fn)

    A hook that is run before updating a single instance

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with instance, options

    A hook that is run after updating a single instance

    Params:


    beforeBulkCreate(name, fn)

    View code

    A hook that is run before creating instances in bulk

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with instances, options

    afterBulkCreate(name, fn)

    A hook that is run after creating instances in bulk

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with instances, options

    beforeBulkDestroy(name, fn)

    View code

    A hook that is run before destroying instances in bulk

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with options

    Aliases: beforeBulkDelete


    afterBulkDestroy(name, fn)

    A hook that is run after destroying instances in bulk

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with options

    Aliases: afterBulkDelete


    beforeBulkRestore(name, fn)

    View code

    A hook that is run before restoring instances in bulk

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with options

    afterBulkRestore(name, fn)

    A hook that is run after restoring instances in bulk

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with options

    beforeBulkUpdate(name, fn)

    View code

    A hook that is run before updating instances in bulk

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with options

    afterBulkUpdate(name, fn)

    A hook that is run after updating instances in bulk

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with options

    beforeFind(name, fn)

    View code

    A hook that is run before a find (select) query

    Params:

    NameTypeDescription
    nameString
    fnFunctionA 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:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with options

    beforeFindAfterOptions(name, fn)

    View code

    A hook that is run before a find (select) query, after all option parsing is complete

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with options

    afterFind(name, fn)

    View code

    A hook that is run after a find (select) query

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with instance(s), options

    View code

    A hook that is run before a count query

    Params:


    beforeDefine(name, fn)

    A hook that is run before a define call

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with attributes, options

    afterDefine(name, fn)

    View code

    A hook that is run after a define call

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with factory

    beforeInit(name, fn)

    A hook that is run before Sequelize() call

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with config, options

    afterInit(name, fn)

    View code

    A hook that is run after Sequelize() call

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with sequelize

    beforeConnect(name, fn)

    A hook that is run before a connection is created

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with config passed to connection

    afterConnect(name, fn)

    View code

    A hook that is run after a connection is created

    Params:

    NameTypeDescription
    nameString
    fnFunctionA 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:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with options passed to Model.sync

    beforeConnect(name, fn)

    View code

    A hook that is run before a connection is created

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with config passed to connection

    beforeSync(name, fn)

    A hook that is run before Model.sync call

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with options passed to Model.sync

    afterSync(name, fn)

    View code

    A hook that is run after Model.sync call

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with options passed to Model.sync

    beforeBulkSync(name, fn)

    A hook that is run before sequelize.sync call

    Params:

    NameTypeDescription
    nameString
    fnFunctionA callback function that is called with options passed to sequelize.sync

    afterBulkSync

    View code

    A hook that is run after sequelize.sync call

    NameTypeDescription
    nameString
    fnFunctionA 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