问题
I have a blank sails 0.9.8 app with a very basic model:
module.exports = {
attributes: {
nickname: 'string',
encryptedPassword: 'string',
beforeCreate: function(values, next){
values.encryptedPassword = "123";
next();
}
}
};
When I create a new User from the console, the beforeCreate method is not called, thus no encryptedPassword created.
I'm sure I'm missing a little something here but cannot find out what. Any idea ?
回答1:
You have to place beforeCreate outside of the attributes. See https://github.com/balderdashy/sails-docs/blob/master/models.md#lifecycle-callbacks
来源:https://stackoverflow.com/questions/21093104/sailsjs-beforecreate-is-not-triggered