typescript-express-sequelize
typescript-express-sequelize copied to clipboard
How to define instance methods in models files.?
Hey,
I was going through your example of sequelize models. I am unable to understand how to write instance methods that require querying other models.
I have a doubt while writing the instance methods on a model. Let us assume there is a user model
and a user has the option to create todos. Now a user can have many todos. How to write a function in the user models that returns the number of todos a user has. Example
instanceMethods: {
countTodos: function() {
// returns total number of todos of a user.
}
}
@vidur149 +1