Sequelize默认排除

时间:2017-10-30 17:32:21

标签: node.js orm sequelize.js

我有一个名为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']
  }
});

但这确实有效。是否还有其他方法可以在默认情况下排除列?

1 个答案:

答案 0 :(得分:11)

我把它搞得一团糟。 exclude需要attributes部分:

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