Skip to content

Instantly share code, notes, and snippets.

@milosdakic
Created September 5, 2013 08:34
Show Gist options
  • Save milosdakic/6447492 to your computer and use it in GitHub Desktop.
Save milosdakic/6447492 to your computer and use it in GitHub Desktop.
Sequelize model mixins
var User = sequelize.define('User', {
name: Sequelize.STRING
}, {
// define the mixins you want to include
// could be similar to sequelize.import()
mixins: [
'CreatedAt',
...
]
] });
// mixin definition
var CreatedAt = {
// if this was some sort of default in the model
beforeSave: function() {
this.call('setCreatedAt');
},
setCreatedAt: function() {
this.setDataValue('createdAt', Utils.now());
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment