Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Sequelize.js ENUM Values from Already Defined Model

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?

like image 992
Jon Saw Avatar asked Mar 12 '14 03:03

Jon Saw


1 Answers

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 
like image 145
Jon Saw Avatar answered Sep 18 '22 19:09

Jon Saw