loopbackio/loopback-connector-postgresql

Query with AND & OR combination is not working

vineet-suri opened this issue · 2 comments

Steps to reproduce

I am trying to execute this code for the find repository method (which accepts FILTER)

filter = { 
      where: {and: [{or: [{userId:'3dc67467-1d37-a1de-9669-5565d5f356fe'}, {connectionUserId: '3dc67467-1d37-a1de-9669-5565d5f356fe'}]}, {status:"ACCEPTED"}]} 
    }; 
this.connectionRepository.find(filter); 

Current Behavior

I am getting this SQL for the above query:

SQL: SELECT "id","user_id","connection_user_id","status" FROM "main"."connections" WHERE ("status"=$1) ORDER BY "id" 
Parameters: ["ACCEPTED"] 

OR clause is completely skipped .

Expected Behavior

However, when i am trying to execute same query for count method of repository (which accepts WHERE clause, the correct SQL is executed.

Code:

this.connectionRepository.count( 
      {and: [{or: [{userId: '3dc67467-1d37-a1de-9669-5565d5f356fe'}, {connectionUserId:'3dc67467-1d37-a1de-9669-5565d5f356fe'}]}, {status: "ACCEPTED"}]}); 

SQL query executed

SQL: SELECT count(*) as "cnt" FROM "main"."connections" WHERE (("user_id"=$1) OR ("connection_user_id"=$2)) AND ("status"=$3) 
Parameters: ["3dc67467-1d37-a1de-9669-5565d5f356fe","3dc67467-1d37-a1de-9669-5565d5f356fe","ACCEPTED"] 

The same should happen for the find method also.

Additional information

linux x64 12.15.0

There are related fixes in PR #466 and loopbackio/loopback-connector#185. Could you please verify it if it works for you? Thanks.

Closing as duplicate of loopbackio/loopback-next#6779.