在Sequelize中,钩子是通过异步方式调用的,因此完成后需要调用完成回调:
userSchema.beforeCreate(function(model, options, cb) { debug('Info: ' + 'Storing the password'); model.generateHash(model.password, function(err, encrypted) { if (err) return cb(err); debug('Info: ' + 'getting ' + encrypted); model.password = encrypted; debug('Info: ' + 'password now is: ' + model.password); return cb(null, options); });});(或者,您可以从挂钩中返回一个承诺)



