My database in not updating in Sequelize

送分小仙女□ 提交于 2019-12-25 01:18:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!