typescript-express-sequelize icon indicating copy to clipboard operation
typescript-express-sequelize copied to clipboard

How to define instance methods in models files.?

Open vidur149 opened this issue 7 years ago • 1 comments

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 avatar Jul 28 '17 06:07 vidur149

@vidur149 +1

rimiti avatar Aug 03 '18 16:08 rimiti