title: Sequelize: Before Create Hook is Not Working As Intended
body: <p>I'm trying to perform a beforeCreate operation on a model that I created via Sequelize. I'm trying to have the password and salt saved before creating the user. However, the user is created without the encrypted password or salt. I'm not too familiar with Node.JS but I'm assuming this has to do with it's asynchronous nature. Any idea how to properly introduce a callback so that my create function behaves as intended? </p>
  
  <p>Model:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>'use strict';
  var Promise = require("bluebird"); 
  var bcrypt =Promise.promisifyAll(require("bcrypt-nodejs"));
  const SALT_ROUNDS = 10; 
  
  module.exports = function(sequelize, DataTypes) {
    var User = sequelize.define('User', {
      username: { type: DataTypes.STRING, unique: true, allowNull: false, validate: { notEmpty: true } }, 
      email: { type: DataTypes.STRING, unique: true, allowNull: false, isEmail: true },
      phone_number: DataTypes.STRING,
      password_hash: { type: DataTypes.STRING, allowNull: false, unique: true, validate: { notEmpty: true } }, 
      password_salt: DataTypes.STRING,
      first_name: DataTypes.STRING,
      last_name: DataTypes.STRING,
      user_type: DataTypes.INTEGER,
      two_factor_enabled: { type: DataTypes.BOOLEAN, defaultValue: false, },
      email_verified: DataTypes.DATE,
      active: { type: DataTypes.BOOLEAN, defaultValue: true, },
    }, {
      classMethods: {
        associate: function(models) {
          // associations can be defined here
        },
        validPassword: function(password, passwd, callback) {
          bcrypt.compare(password, passwd, function(err, isMatch) {
            if (isMatch) {
              return callback(null, true);
            } else {
              return callback(null, false); 
            }
          });
        },
      },
      hooks: {
   beforeCreate: function(user, {}) {
    bcrypt.genSalt(SALT_ROUNDS, function(err, salt) {
     bcrypt.hash(user.password_hash, salt, function(){}, function(err, hash) {
      if (err) {
       return sequelize.Promise.reject(err); 
      }
  
             user.setDataValue('password_hash',hash);
      user.setDataValue('password_salt',salt);
     });
  
    });
   }
      },
      instanceMethods: {
   generateHash: function(password) {
    return bcrypt.hashSync(password, bcrypt.genSaltSync(10), null); 
   },
   validPassword: function(password) {
    return bcrypt.compareSync(password, this.password); 
   }
      }
    });
  
    //User.associate = (models) =&gt; {
    //  User.hasMany(models.UserType, {
    //    foreignKey: 'userId',
    //    as: 'userTypes'
    //  });
    //};
  
    return User;
  };</code></pre>
  </div>
  </div>
  </p>
  
  <p>And here's the call:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>return db.User
     .create({
      first_name: req.body.first_name,
      last_name: req.body.last_name, 
      username: req.body.username,
      email: req.body.email, 
      password_hash: req.body.password 
     })
     .then(user =&gt; res.status(201).send(user))
     .catch(error =&gt; res.status(400).send(error));
    },</code></pre>
  </div>
  </div>
  </p>