node.js - 断言错误 [ERR_ASSERTION] : Missing where attribute in the options parameter

标签 node.js express sequelize.js

我正在尝试更新我的数据库它没有给出任何错误但它没有在数据库中更新

执行(默认): SELECT idtitleslugcontentsortingcreatedAtupdatedAt FROM Pages AS Page WHERE Pageid = '52';

执行(默认): SELECT idtitleslugcontentsortingcreatedAtupdatedAt FROM Pages AS Page WHERE Pageid = '关于我们';

我的模型名称是页面,当我尝试进入编辑表单时,我正在打印这些值并且它的工作正常

谢谢

        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/

相关文章:

javascript - 你如何从 getInitialProps 中的 url 获取查询参数?

javascript - Express 的 res.end() 是如何工作的?

javascript - 在where子句中进行sequelize join来关联两个表

node.js - 回调 Passport Sequelize 的 404 错误

node.js - 我的 express https 服务器在本地工作但不在 docker 容器中

node.js - 如何在 node-pdfkit 中使用异步函数?

node.js - Sequelize 未找到 SQL Server 主机错误

mysql - MySQL表中的created_At字段可以编辑吗?

javascript - Windows 上的 Git Hook 无法识别 Node

node.js - Mongodb 架构/模型中文件的字段类型是什么?