从之前的SO discussion开始,我能够使用两个条件更新多个续集实例。
任何人都可以解释如何使用逻辑OR运算符而不是AND运算符修改sequelize .update方法吗?下面是使用AND的sequelize .update方法,用于更新的两个条件。
global.db.Task.update(
{Desc: 'New Upate'}, //set attribute
{cd: 'match', Desc: null} //where criteria
).success(function(affectedRows) { ... });
这将读取SQL语句如下:
UPDATE "Task" SET "Desc"='New Update' WHERE "Cd"='match' AND "Desc" IS NULL
答案 0 :(得分:1)
尝试
global.db.Task.update(
{Desc: 'New Upate'}, //set attribute
["cd = ? OR Desc = ?", 'match', null] //where criteria
).success(function(affectedRows) { ... });
更新(来自Miller):添加了我在设置属性行末尾遗漏的逗号。
答案 1 :(得分:0)
global.db.Task.update({update_data},{where:{where_data}})。then(function(affectedrows){})
global.db.Task.update({Desc: 'New Upate'}, where: {$or: [{cd: "match"}, {Desc: null}]}).success(function(affectedRows) { ... });