问题
i am trying to use this code to update my values but when i res.json it gives me [0] any one who can help me with this problem. Thanks in advance.
var condition={
where:
{id:req.params.id}
};
var values={
title:req.body.title,
slug:req.body.slug,
content:req.body.content
};
options={multi:true};
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,condition,options)
.then(function(page){
res.render('admin/pages/edit-page');
})
.catch(function(err){
console.log(err);
})
}
});
回答1:
As per the doc update accepts only 2 params and in your function you are sending 3
Change this :
models.Page.update(values,condition,options)
To :
models.Page.update(values,{ ...condition, ...options }) // ES6 sprade operator
来源:https://stackoverflow.com/questions/50011964/my-database-in-not-updating-in-sequelize