【问题标题】:Sequelize Default ExcludeSequelize 默认排除
【发布时间】:2018-04-11 18:39:01
【问题描述】:

我有一个名为 person 的表,我希望默认排除一列,

const Person = sequelize.define('person',{
  secretColumn: Sequelize.STRING,
  //... and other columns
});

我看到 Sequelize 中有一个名为Scope 的功能: http://docs.sequelizejs.com/manual/tutorial/scopes.html

我试图这样排除;

const Person = sequelize.define('person',{
  secretColumn: Sequelize.STRING,
  //... and other columns
}, {
  defaultScope: {
    exclude: ['secretColumn']
  }
});

但这不起作用。有没有其他方法可以默认排除一列?

【问题讨论】:

    标签: node.js orm sequelize.js


    【解决方案1】:

    我想通了。 exclude 需要在 attributes 部分:

    const Person = sequelize.define('person',{
      secretColumn: Sequelize.STRING,
      //... and other columns
    }, {
      defaultScope: {
        attributes: { exclude: ['secretColumn'] }
      }
    });
    

    【讨论】:

    • 不知道为什么,但这对我不起作用。这样做可以吗? defaultScope: { 属性: { exclude: ['token', 'access', 'password'] } }
    猜你喜欢
    • 2016-12-23
    • 1970-01-01
    • 2020-12-05
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多