{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/4117","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/4117/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/4117/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/4117/events","html_url":"https://github.com/sequelize/sequelize/issues/4117","id":95157035,"number":4117,"title":"beforeCreate unable to modify model","user":{"login":"lucaschenex","id":2229985,"avatar_url":"https://avatars.githubusercontent.com/u/2229985?v=3","gravatar_id":"","url":"https://api.github.com/users/lucaschenex","html_url":"https://github.com/lucaschenex","followers_url":"https://api.github.com/users/lucaschenex/followers","following_url":"https://api.github.com/users/lucaschenex/following{/other_user}","gists_url":"https://api.github.com/users/lucaschenex/gists{/gist_id}","starred_url":"https://api.github.com/users/lucaschenex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucaschenex/subscriptions","organizations_url":"https://api.github.com/users/lucaschenex/orgs","repos_url":"https://api.github.com/users/lucaschenex/repos","events_url":"https://api.github.com/users/lucaschenex/events{/privacy}","received_events_url":"https://api.github.com/users/lucaschenex/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-15T10:15:55Z","updated_at":"2015-07-15T16:44:02Z","closed_at":null,"body":"I defined my hook beforeCreate as following:\r\n\r\n    module.exports = function (sequelize, DataTypes) {\r\n      var userSchema = sequelize.define('User', {\r\n      // define...\r\n      });\r\n      userSchema.beforeCreate(function (model) {\r\n        debug('Info: ' + 'Storing the password');    \r\n        model.generateHash(model.password, function (err, encrypted) {\r\n          debug('Info: ' + 'getting ' + encrypted);\r\n \r\n          model.password = encrypted;\r\n          debug('Info: ' + 'password now is: ' + model.password);\r\n          // done;\r\n        });\r\n      });\r\n    };\r\n\r\nand when I create a the model\r\n\r\n      User.create({\r\n        name:           req.body.name.trim(),\r\n        email:          req.body.email.toLowerCase(),\r\n        password:       req.body.password,\r\n        verifyToken:    verifyToken,\r\n        verified:       verified\r\n      }).then(function (user) {\r\n        debug('Info: ' + 'after, the password is ' + user.password);    \r\n      }).catch(function (err) {\r\n        // catch something\r\n      });\r\n\r\nNow what I get from this is \r\n\r\n    Info: Storing the password +6ms\r\n    Info: hashing password 123123 +0ms    // debug info calling generateHash()\r\n    Executing (default): INSERT INTO \"Users\" (\"id\",\"email\",\"password\",\"name\",\"verified\",\"verifyToken\",\"updatedAt\",\"createdAt\") VALUES (DEFAULT,'wwx@test.com','123123','wwx',true,NULL,'2015-07-15 09:55:59.537 +00:00','2015-07-15 09:55:59.537 +00:00') RETURNING *;\r\n\r\n    Info: getting $2a$10$6jJMvvevCvRDp5E7wK9MNuSRKjFpieGnO2WrETMFBKXm9p4Tz6VC. +0ms\r\n    Info: password now is: $2a$10$6jJMvvevCvRDp5E7wK9MNuSRKjFpieGnO2WrETMFBKXm9p4Tz6VC. +0ms\r\n    Info: after, the password is 123123 +3ms\r\n\r\nIt seems that every part of the code is working. Creating a user schema will invoke beforeCreate, which properly generates the hash code for the password.... except it didn't write to the database!\r\n\r\nI'm certain that I'm missing a very important and OBVIOUS piece of code, but I just can't find where the problem is (aghh). Any help appreciated!"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/121674684","html_url":"https://github.com/sequelize/sequelize/issues/4117#issuecomment-121674684","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/4117","id":121674684,"user":{"login":"lucaschenex","id":2229985,"avatar_url":"https://avatars.githubusercontent.com/u/2229985?v=3","gravatar_id":"","url":"https://api.github.com/users/lucaschenex","html_url":"https://github.com/lucaschenex","followers_url":"https://api.github.com/users/lucaschenex/followers","following_url":"https://api.github.com/users/lucaschenex/following{/other_user}","gists_url":"https://api.github.com/users/lucaschenex/gists{/gist_id}","starred_url":"https://api.github.com/users/lucaschenex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucaschenex/subscriptions","organizations_url":"https://api.github.com/users/lucaschenex/orgs","repos_url":"https://api.github.com/users/lucaschenex/repos","events_url":"https://api.github.com/users/lucaschenex/events{/privacy}","received_events_url":"https://api.github.com/users/lucaschenex/received_events","type":"User","site_admin":false},"created_at":"2015-07-15T16:44:02Z","updated_at":"2015-07-15T16:44:02Z","body":"That's exactly where the problem is. Hmmm interesting.."}}