Sequelize Model.update with include where

时间:2017-10-22 16:06:49

标签: sequelize.js

我想根据JobCard模型状态

设置Cars模型的状态
        Cars.update({
            status: 'done'
        },
        {
            where: {
                status: 'pending'
            },
        },
        {
            include: [
                {
                    model: sequelize.models.JobCard,
                    where: {
                        id: jobcard_id
                    }
                }
            ]
        })
        .then((result) => {
            console.log(result);
        });

但是在日志中我只看到了这个查询

 UPDATE "Cars" SET "status"='done',"updatedAt"='2017-10-22 15:57:24.854 +00:00' WHERE "status" = 'pending';

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

include属性应该是options对象的一部分(第二个参数传递给.update()指定的where方法),例如:

Cars.update({
        status: 'done'
    },
    {
        where: {
            status: 'pending'
        },
        include: [
            {
                model: sequelize.models.JobCard,
                where: {
                    id: jobcard_id
                }
            }
        ]
    }

但是,据我所知,Sequelize不支持使用include作为传递给.update()方法的options参数的一部分。每次我尝试这样做,即使是现在(在Sequelize v4.42.0中),都将引发错误,并且查询未成功完成。

相关问题