Skip to content

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

Open
@vidur149

Description

@vidur149

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.
      }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions