Get Sequelize.js ENUM Values from Already Defined Model

后端 未结 1 856
长情又很酷
长情又很酷 2021-02-11 16:12

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:          


        
相关标签:
1条回答
  • 2021-02-11 17:05

    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
    
    0 讨论(0)
提交回复
热议问题