【问题标题】:accessing instance method from findOne in sequelize 5在 sequelize 5 中从 findOne 访问实例方法
【发布时间】:2020-01-01 00:00:46
【问题描述】:

我有一个模型的实例方法,即 isAdmin(),但我无法像在 sequelize 3 中那样直接访问它。

这是sn-p:

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

【问题讨论】:

    标签: node.js sequelize.js


    【解决方案1】:

    您如何定义isAdmin() 方法?这是一个适合我的示例:

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

    【讨论】:

      猜你喜欢
      • 2017-10-12
      • 1970-01-01
      • 2015-07-09
      • 1970-01-01
      • 2013-10-26
      • 1970-01-01
      • 2014-01-26
      • 2017-05-12
      • 2019-03-15
      相关资源
      最近更新 更多