【发布时间】:2017-07-07 20:57:47
【问题描述】:
我正在制作一个包含更新过去帖子的应用。为此有一个单独的页面和一条路线。
app.post("/posts/:id/update", function(req, res){
Post.findAll({
where: {
id: req.params.id
}
}).then(function(foundPost){
var updatePost = foundPost[0]
updatePost.updateAttributes({
description: req.params.description,
author: req.params.author,
image: req.params.image
})
});
res.redirect("/posts")
});
此代码将在数据库中找到帖子,然后尝试使用从更新页面上的表单接收到的数据进行更新。由于某种原因,除了数据库中的“updatedAt”日期之外,帖子根本没有更新。这是尝试更新帖子后从终端输出的内容:
Executing (default): UPDATE `posts` SET `updatedAt`='2017-07-07 20:50:22' WHERE `id` = 4
它找到了正确的帖子,但没有做任何事情。
【问题讨论】:
标签: mysql node.js express sequelize.js