A2MetalCore
A2MetalCore

Reputation: 1639

Inconsistent Results Using Loopback Count End-Point With Filter+Where vs. Just Where

We're getting unexpected and inconsistent results when using Loopback's count end-point. Using filter[where] always returns the total number of rows in the table, ignoring any filter. For example, the following call always returns a value of 9 which is not correct (given the data below):

/api/class/count?filter[where][companyrowid]=1

Class Table Data (MySQL)

rowid  description         companyrowid
3367   test1                0             
3366   test2                0             
3364   Asia Division        1             
3365   Australia Division   1             
3362   Canada Division      1             
3363   Europe Division      1             
3359   US East Division     1             
3361   US Midwest Division  1             
3360   US West Division     1

Strangely, using 'where[companyid]=1' returns the correct value of 7. Close inspection of the http request object shows that filter[where][...] and where[..] filters are actually stored separately and yield different results:

/api/class/count?filter[where][companyrowid]=1
  1. req.query.filter.where = {companyid: "1"}
  2. req.query.where = undefined
  3. Result: 9 (incorrect)

/api/class/count?where[companyrowid]=1

  1. req.query.filter.where = undefined
  2. req.query.where = {companyid: "1"}
  3. Result: 7 (correct)

The biggest issue is the filter[where] ignoring the filter.

Upvotes: 0

Views: 862

Answers (1)

RootHacker
RootHacker

Reputation: 1107

count() method only takes the where clause instead of the filter. So your REST API should be like this

/api/class/count?[where][companyrowid]=1

Upvotes: 3

Related Questions