从已定义的模型中获取Sequelize.js ENUM值

时间:2014-03-12 03:00:09

标签: node.js enums sequelize.js

在Sequelize.js中定义模型后如何获取模型的ENUM值?

例如,我们将模型定义为:

sequelize.define('model', {
  states: {
    type:   Sequelize.ENUM,
    values: ['active', 'pending', 'deleted']
  }
})

我们如何从此模型中获取预定义的['active', 'pending' ,'deleted']值?

1 个答案:

答案 0 :(得分:41)

模式中的ENUM值可以在模型的rawAttributes属性中找到。

var Model = sequelize.define('model', {
  states: {
    type:   Sequelize.ENUM,
    values: ['active', 'pending', 'deleted']
  }
});

console.log(Model.rawAttributes.states.values);
// logs ['active', 'pending', 'deleted'] in console