feathersjs-ecosystem/feathers-objection

Wrong result total if modifiers are used

nakedgun opened this issue · 4 comments

  1. Add a modifier to a service model, e.g:
test(builder) {
  builder.where('id', 1)
},
  1. Use the modifier when calling find({})
await Model.find({
query: {
  $modify: 'test'
 }
});

result:

 {
  "total": 102,  <--- wrong (expected: 1)
  "limit": 10,
  "skip": 0,
  "data": [
    {
      “id”: 1
    }
  ]
}

...which breaks client pagination.

expected:

The total returned is based upon the count of the query with the modifiers (e.g. 1).

This is similar (in principal) to this case: feathersjs-ecosystem/feathers-knex#121

I hacked together a proof of concept solution based upon the thread above which returns the correct total. This is based upon cloning the actual query and running it as a count query with no limit. Not sure if that's the correct approach though? Any help is appreciated!

@nakedgun Thanks!

The $modify query operator in v5.5.1 now also applies on the count query.

Awesome, thanks @dekelev for the fix -- appreciated!

@dekelev I see the 5.5.1 release on github, but not on NPM. Would you mind publishing it?

@nakedgun Sorry, it's published now.