簡體   English   中英

Sequelize Op.or 與兩個 Op.and

[英]Sequelize Op.or with two Op.and

我需要像這樣獲取 WHERE 查詢:

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

在續集中我寫道:

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

但我得到:

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

試試這樣:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM