sailsjs beforeCreate is not triggered

◇◆丶佛笑我妖孽 提交于 2019-12-10 12:59:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!