在 Sequelize 5 中,我的实例看起来像:
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
}
在 Sequelize 6 中,我没有 _modelOptions。如何获取模型信息 (_modelOptions)?它是必需的,因为该实例可能是多个不同模型之一。
最佳答案
我在这里找到了解决方案:
https://github.com/sequelize/sequelize/issues/12486
用
recentItem.constructor.options
关于sequelize.js - 在 Sequelize 6 中获取 instance._modelOptions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62802524/