sequelize/sequelize — pull request #2320 by overlookmotel (2014-09-22 02:12:21+00:00)
Title: Universal hooks for all models + hooks on Sequelize#define and Sequelize()

More hooks stuff! This PR...

#### 1. Allows hooks to be defined on all models

sequelize.addHook('beforeCreate', function(...) {...});

This hook is then run on any model when a new instance is created.

#### 2. Creates hooks on `Sequelize.define` (`beforeDefine` and `afterDefine`)

#### 3. Creates hooks on `Sequelize()` (`beforeInstantiate` and `afterInstantiate`)

Sequelize.addHook('beforeInstantiate', function(config, options) {
config.database = 'db8';
});

var sequelize = new Sequelize('db1', 'user', 'password');
// the database name is overriden by the hook

My use case for (3) is for a plugin to define universal hooks when it initializes:

Sequelize.addHook('afterInstantiate', function(sequelize) {
sequelize.addHook('beforeFind', function(options) {...});
});

#### 4. Allows for hooks running sync for sync functions

This was neccesary to put hooks on `Sequelize#define` and `Sequelize()` as they are not async functions.