Created
September 5, 2013 08:34
-
-
Save milosdakic/6447492 to your computer and use it in GitHub Desktop.
Sequelize model mixins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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