Sequelize OR condition object Sequelize OR condition object node.js node.js

Sequelize OR condition object


Seems there is another format now

where: {    LastName: "Doe",    $or: [        {            FirstName:             {                $eq: "John"            }        },         {            FirstName:             {                $eq: "Jane"            }        },         {            Age:             {                $gt: 18            }        }    ]}

Will generate

WHERE LastName='Doe' AND (FirstName = 'John' OR FirstName = 'Jane' OR Age > 18)

See the doc: http://docs.sequelizejs.com/en/latest/docs/querying/#where


String based operators will be deprecated in the future (You've probably seen the warning in console).

Getting this to work with symbolic operators was quite confusing for me, and I've updated the docs with two examples.

Post.findAll({  where: {    [Op.or]: [{authorId: 12}, {authorId: 13}]  }});// SELECT * FROM post WHERE authorId = 12 OR authorId = 13;Post.findAll({  where: {    authorId: {      [Op.or]: [12, 13]    }  }});// SELECT * FROM post WHERE authorId = 12 OR authorId = 13;


Use Sequelize.or:

var condition = {  where: Sequelize.and(    { name: 'a project' },    Sequelize.or(      { id: [1,2,3] },      { id: { lt: 10 } }    )  )};

Reference (search for Sequelize.or)

Edit: Also, this has been modified and for the latest method see Morio's answer,