问题
How do we get the ENUM values of a model after defining it in Sequelize.js?
For example, we define our model as:
sequelize.define('model', {
states: {
type: Sequelize.ENUM,
values: ['active', 'pending', 'deleted']
}
})
How do we get the pre-defined ['active', 'pending' ,'deleted'] values from this model?
回答1:
The ENUM values in a schema can be found in the rawAttributes property of the model.
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
来源:https://stackoverflow.com/questions/22341138/get-sequelize-js-enum-values-from-already-defined-model