gpt4 book ai didi

sequelize.js - Sequelize Update、After Create Hook 和 Literal Date

转载 作者:行者123 更新时间:2023-12-03 22:22:35 24 4
gpt4 key购买 nike

在 Sequelize 中,我有一个模型 WorkFile具有以下实例方法

workfile.update({ path: '/path/to/here' }).then(result => {
return result;
})

这很好用,除了 result包含以下内容
{
"created_at": "2017-03-02T16:32:42.542Z",
"updated_at": {
"val": "NOW()"
},
// etc
}

更新方法有效,但 updated_at仍然是分贝文字。 只有当我有 afterCreate 时才会发生这种情况 Hook 模型。 我试过 workfile.get() , workfile.get({ plain: true }) .我唯一能做的就是重新查询数据库中的对象,这看起来很荒谬。有没有办法在没有文字 updated_at 的情况下访问对象?

已编辑

这是钩子(Hook):
afterCreate: function(workfile, options, cb) {
return workfile.update({
path: `path/with/${workfile.id}`
})
.then(wf => cb(null, workfile)) // <--workfile and wf both have literal updated_at
.catch(err => cb(err));
}

最佳答案

对于那些 future 的人,在我的模型中,我使用了 Sequelize.literal('NOW()') .当我用 Sequelize.NOW 替换它时,问题就解决了。不完全确定为什么,但它可以作为修复!

关于sequelize.js - Sequelize Update、After Create Hook 和 Literal Date,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42561057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com