2017-07-07 50 views
-1

SQL查詢工作正常,但在節點js中使用suquelize orm查詢不起作用。SQL將序列化ORM查詢更改

SQL:沃金精

select message from tbl_chat where (userId=1 or userId=98) and (receiverId=1 or receiverId=98) and isgroupChat=0; 

Sequelize ORM:不工作

   let result = await Chat.findAll<Chat>({ 

      where: { 
       isgroupChat: 0, 
       $and: { 
        $or: [ 
         { 
          userId: userId 
         }, 
         { 
          userId: userId 
         } 
        ], 
        $or: [ 
         { 
          receiverId: receiverId 
         }, 
         { 
          receiverId: receiverId 
         } 
        ] 
       } 
      } 
     }); 
+0

什麼查詢是orm生成的 – Shivam

+0

「Not working」_how?_ –

回答

0

不知道到底爲什麼這是行不通的。打開日誌記錄並查看ORM爲查詢生成的內容。但是,我也嘗試更改一下這個查詢:

{ 
    where: { 
    isGroupChat: 0, 
    userId: { $in: [uid1, uid2] }, 
    receiverId: { $in: [uid1, uid2] } 
}