AssertionError [ERR_ASSERTION]:缺少options参数中的where属性

时间:2018-04-24 21:01:13

标签: node.js express sequelize.js

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

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

执行(默认):SELECT idtitleslugcontentsortingcreatedAtupdatedAt来自Pages AS Page WHERE Pageid ='about-uss';

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

由于

        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);
                })
            }
            });

2 个答案:

答案 0 :(得分:0)

当您更新任何模型时,您应该具有正确的设置值作为键值对,就像定义条件一样。如果您要更新多个目的,则必须将可选的多选项设置为true。您应该记录update函数返回的结果。

var values = {title: 'some title' , content : 'P' };
var condition = { where :{id: 2} }; 
options = { multi: true };

models.Page.update(values, condition , options)
. then(function(upresult) {} ) 

答案 1 :(得分:0)

要一次更新所有行,请为where提供一个空对象。 在此处查看答案:https://stackoverflow.com/a/55388332/7668448