Reputation: 31
how do we create custom instance methods to be applied/inherited by all models with sequelize 4.2? In sequelize 3 we used to have an "instanceMethods: {custom1: function (){} }" in the "define" section of a main model which was extended to all other models. How do we achieve the same behaviour with sequelize 4.0?
Upvotes: 1
Views: 377
Reputation: 64
Instance methods get called independently of the "define" section now. I just got mine to work on V4 by doing something like this:
const User = sequelize.define('users', {
name: {type: Sequelize.TEXT}
});
User.prototype.custom1 = function() {
//function
};
I can still call the instance method in any file in which the User model is imported. I hope this helps! This is the doc I used for reference:
Upvotes: 1