Code Stud
Code Stud

Reputation: 17

accessing instance method from findOne in sequelize 5

I have an instance method namely isAdmin() of a model,but I am unable to access it directly like in sequelize 3.

Here's the snippet:

 BranchUser.findOne({ where: {branchUserBranchId: userid} }).then(user => {
                    console.log('user:  ',user.isAdmin());
                });

Upvotes: 0

Views: 144

Answers (1)

KenOn10
KenOn10

Reputation: 1968

How are you defining the isAdmin() method? Here's an example that works for me:

BranchUser.prototype.isAdmin = function () {
  // sample instance code here:
  if (this.adminFlag) {   
     console.log('yes, I am an admin.  thanks for asking');
  }
}

Upvotes: 1

Related Questions