Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sequelize Op.or with two Op.and

I need get WHERE query like this:

WHERE (x = 1 AND y = 2) OR (x = 2 AND y = 1)

In sequelize i write:

where: {
          [Op.or]: {
            [Op.and]: {
              ownerId: candidate.recipientId,
              recipientId: candidate.senderId,
            },
            [Op.and]: {
              recipientId: candidate.recipientId,
              ownerId: candidate.senderId,
            },
          },
        },

But i get:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

WHERE (("Chat"."recipient_id" = 2 AND "Chat"."owner_id" = 1))

>Solution :

Try this way:

where: {
  [Op.or]: [{
    ownerId: candidate.recipientId,
    recipientId: candidate.senderId,
  },{
    recipientId: candidate.recipientId,
    ownerId: candidate.senderId,
  }]
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading