Skip to content

Commit

Permalink
Fix countBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
CITIZENDOT committed Aug 15, 2024
1 parent 6330134 commit a41ce21
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/knex/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,11 @@ export class KnexAdapter<
async _find(params?: ServiceParams): Promise<Paginated<Result> | Result[]>
async _find(params: ServiceParams = {} as ServiceParams): Promise<Paginated<Result> | Result[]> {
const { filters, paginate } = this.filterQuery(params)
const { name, id } = this.getOptions(params)
const { Model, name, id } = this.getOptions(params)
const builder = params.knex ? params.knex.clone() : this.createQuery(params)
const countBuilder = builder.clone().clearSelect().clearOrder().count(`${name}.${id} as total`)

const countBuilder = Model.count(`* as total`)
.with('subquery', builder.clone().clearOrder())
.from('subquery')
// Handle $limit
if (filters.$limit) {
builder.limit(filters.$limit)
Expand Down

0 comments on commit a41ce21

Please sign in to comment.