loopbackio / loopback-connector-elastic-search

Strongloop Loopback connector for Elasticsearch
MIT License
78 stars 56 forks source link

Incorrect usage of where filter in loopback #79

Closed aquid closed 7 years ago

aquid commented 7 years ago

Loopback internally does some model calls with where filter in a wrong pattern. Ideally where filter in loopback should just have single direct property clause and if there are multiple clauses associated with different properties then they all should be inside “and/ or” filter. Proof - I can see a query in ACL which does something like this:

{ 
  Where: { 
    model: 'Category', 
    property: { inq: [ 'count', '*' ] }, 
    accessType: { inq: [ 'READ','*' ] } 
  }
}

While this should be written in a way like this:

{ 
  Where: { 
    and : [
      model: 'Category', 
      property: { inq: [ 'count', '*' ] },
      accessType: { inq: [ 'READ','*' ]}
    ] 
  }
}

This I guess wrong and maybe we can send a PR to loopback for this. cc @pulkitsinghal

pulkitsinghal commented 7 years ago

Not sure if it is "wrong" or just a convention in loopback and they want us to assume that if nothing is specified then siblings should be treated with an AND

cc @bajtos @aquid

bajtos commented 7 years ago

assume that if nothing is specified then siblings should be treated with an AND

Yes, I believe that's the case. Looks like our test suite does not cover this important use case, would you like to contribute few new tests to fix that? Here is the source where to start: test/basic-querying.test.js#L142 and documentation for new contributors: http://loopback.io/doc/en/contrib/code-contrib.html Please mention my handle (@bajtos) in pull request description so that I can review it sooner.