首页 > 解决方案 > 有没有办法将类应用于 Sequelize 模型中的 JSON 属性?

问题描述

const Payments = sequelize.define('Payments', {
  id: DataTypes.STRING,
  meta: DataTypes.JSON,
}, {
  timestamps: false,
})

async function init() {
  await sequelize.drop()
  await sequelize.sync({ force: true })

  const payment = await Payments.create({
    id: 'payment-id',
    meta: {
      status: 'authorized',
      history: {
        'some-time-stamp': 'some message from service',
        'another-time-stamp': 'payment was received by this guy'
      }
    }
  })
}

Sequelize 是否有办法meta在加载实例时自动将类应用于 JSON 字段?

标签: node.jssequelize.js

解决方案


推荐阅读