Search code examples
node.jsnestjstypeorm

how to find data that (userId = a && friendId = b) AND (userId = b && friendId = a) in typeorm?


how to find data that (userId = a && friendId = b) AND (userId = b && friendId = a) in typeorm ?

enter image description here


Solution

  • Just replace ; in both of your where conditions to AND, e.g.:

    .where("friendMessage.userId = :userId AND friendMessage.userId = :friendId", { userId: item.userId, friendId: item.friendId })
    

    But I'm not sure that it would be correct, because of userId and friendId from item could be different, but for some reason you want to check that both are suitable for friendMessage.userId. I guess OR operator should be used instead of AND