Set raw = true on Sequelize Model.create

前端 未结 3 987
青春惊慌失措
青春惊慌失措 2021-02-08 22:26

I want to be able to receive the plain raw object after calling Model.create on Sequelize, the object itself that was created, no metadata or any other things. Just

3条回答
  •  感情败类
    2021-02-08 22:45

    Model.create(modelObject)
    .then((resultEntity) => {
        const dataObj = resultEntity.get({plain:true})
    }
    

    Like mentioned before or if you want to keep with async/await syntax go for:

    const myResultVar = (await Model.create(modelObject)).get({plain:true})
    

    Basically the same thing just not leaving the async/await syntax behind :)

提交回复
热议问题