DubyaCO
DubyaCO

Reputation: 1

Getting instance._modelOptions in Sequelize 6

In Sequelize 5, my instance would look like:

recentItem {
  dataValues: {
    id: 't4qupOzsuPrxLuHkLiYwA',
    createdAt: 2019-07-23T22:07:43.727Z,
    updatedAt: 2020-07-08T19:30:13.348Z,
    entityId: 'SJleJVAA_z'
  },
  _previousDataValues: {
    id: 't4qupOzsuPrxLuHkLiYwA',
    createdAt: 2019-07-23T22:07:43.727Z,
    updatedAt: 2020-07-08T19:30:00.122Z,
    entityId: 'SJleJVAA_z'
  },
  _changed: { updatedAt: true },
  _modelOptions: {
    timestamps: true,
    validate: {},
    freezeTableName: false,
    underscored: false,
    paranoid: false,
    rejectOnEmpty: false,
    whereCollection: {
      entityId: 'SJleJVAA_z'
    },
    schema: null,
    schemaDelimiter: '',
    defaultScope: {},
    scopes: {},
    indexes: [],
    name: { plural: 'recentItems', singular: 'recentItem' },
    omitNull: false,
    sequelize: Sequelize {
      options: [Object],
      config: [Object],
      dialect: [PostgresDialect],
      queryInterface: [QueryInterface],
      models: [Object],
      modelManager: [ModelManager],
      connectionManager: [ConnectionManager],
      importCache: [Object],
      Op: [Object],
      Promise: [Function]
    },
    hooks: {}
  },
  _options: {
    isNewRecord: false,
    _schema: null,
    _schemaDelimiter: '',
    raw: true,
    attributes: [ 'id', 'createdAt', 'updatedAt', 'entityId' ]
  },
  isNewRecord: false
}

In Sequelize 6, I do not have the _modelOptions. How can I get the model information (_modelOptions)? It's needed because the instance could be one of several different models.

Upvotes: 0

Views: 465

Answers (1)

ShaharMynd
ShaharMynd

Reputation: 31

I found the solution here: https://github.com/sequelize/sequelize/issues/12486

Use

recentItem.constructor.options

Upvotes: 1

Related Questions