我正在尝试更新我的数据库它没有给出任何错误但它没有在数据库中更新
执行(默认): SELECT id
、 title
、 slug
、 content
、 sorting
、 createdAt
、 updatedAt
FROM Pages
AS Page
WHERE Page
。 id
= '52';
执行(默认): SELECT id
、 title
、 slug
、 content
、 sorting
、 createdAt
、 updatedAt
FROM Pages
AS Page
WHERE Page
。 id
= '关于我们';
我的模型名称是页面,当我尝试进入编辑表单时,我正在打印这些值并且它的工作正常
谢谢
var where={
id:req.params.id
};
var values={
title,slug,content
};
var errors = req.validationErrors();
if (errors) {
res.render('admin/edit_page', {
errors: errors,
title: title,
slug: slug,
content: content,
id:id
});
} else {
// models.Page.find({
// where: {
// id:req.params.id
// }
// })
// .then(function(page){
// if(Page){
models.Page.update(values,where)
.then(function(){
title=req.body.title,
slug=req.body.slug,
content=req.body.content
})
.then(function(page){
res.render('admin/pages');
})
.catch(function(err){
console.log(err);
})
}
});
最佳答案
当您更新任何模型时,您应该有一个正确的设置值作为键值对,就像您定义条件的方式一样。如果您的目的是更新多个,则必须将可选的 multi 选项设置为 true。您应该记录更新函数返回的结果。
var values = {title: 'some title' , content : 'P' };
var condition = { where :{id: 2} };
options = { multi: true };
models.Page.update(values, condition , options)
. then(function(upresult) {} )
关于node.js - 断言错误 [ERR_ASSERTION] : Missing where attribute in the options parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50010662/