Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to define instance methods in models files.? #1

Open
vidur149 opened this issue Jul 28, 2017 · 1 comment
Open

How to define instance methods in models files.? #1

vidur149 opened this issue Jul 28, 2017 · 1 comment

Comments

@vidur149
Copy link

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.
      }
    }
@rimiti
Copy link

rimiti commented Aug 3, 2018

@vidur149 +1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants