KSDaemon/sails-hook-sequelize

Sequelize Hooks Support

mrded opened this issue · 2 comments

mrded commented

It would be nice to add Sequelize Hooks to models:

module.exports = {
  attributes: {
    username: DataTypes.STRING,
    mood: {
      type: DataTypes.ENUM,
      values: ['happy', 'sad', 'neutral']
    }
  },
  hooks: function() {
    beforeValidate: (user, options) => {
      user.mood = 'happy';
    },
    afterValidate: (user, options) => {
      user.username = 'Toni';
    }
  },
};

Be careful, hooks are passed as options atributes, so you allready can do this :)

mrded commented

Oh, didn't noticed that. Thank you!