Val
Val

Reputation: 1350

Using sequelize, how do you use an OR operator with the where criteria?

From a previous SO discussion I was able to update multiple sequelize instances with two conditions.

Can anyone explain how I can modify the sequelize .update method using a logical OR operator instead of an AND operator? Below is the sequelize .update method using AND for the two condition of updating.

  global.db.Task.update(
    {Desc: 'New Upate'},       //set attribute 
    {cd: 'match', Desc: null}  //where criteria 
  ).success(function(affectedRows) { ... });

This will read an SQL Statement as follows:

UPDATE "Task" SET "Desc"='New Update' WHERE "Cd"='match' AND "Desc" IS NULL

Upvotes: 1

Views: 739

Answers (2)

vijay kumar
vijay kumar

Reputation: 1055

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

Upvotes: 0

Kamrul
Kamrul

Reputation: 7301

try

global.db.Task.update(
    {Desc: 'New Upate'},       //set attribute 
    ["cd = ? OR Desc = ?", 'match', null]  //where criteria 
  ).success(function(affectedRows) { ... });

Update (from Miller): Added a comma that I missed in at the end of the set attribute line.

Upvotes: 1

Related Questions