1

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
Community
  • 1
  • 1
Val
  • 1,260
  • 5
  • 23
  • 39

2 Answers2

1

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.

Val
  • 1,260
  • 5
  • 23
  • 39
Kamrul
  • 7,175
  • 3
  • 31
  • 31
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) { ... });
vijay kumar
  • 1,025
  • 13
  • 11