Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sailsjs beforeCreate is not triggered

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 ?

like image 760
Luc Avatar asked Jan 13 '14 14:01

Luc


1 Answers

You have to place beforeCreate outside of the attributes. See https://github.com/balderdashy/sails-docs/blob/master/models.md#lifecycle-callbacks

like image 98
tarlepp Avatar answered Oct 20 '22 13:10

tarlepp