在Sequelize.js中定义模型后如何获取模型的ENUM值?
例如,我们将模型定义为:
sequelize.define('model', {
states: {
type: Sequelize.ENUM,
values: ['active', 'pending', 'deleted']
}
})
我们如何从此模型中获取预定义的['active', 'pending' ,'deleted']
值?
答案 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