Skip to content

Commit a41ce21

Browse files
committed
Fix countBuilder
1 parent 6330134 commit a41ce21

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/knex/src/adapter.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,11 @@ export class KnexAdapter<
166166
async _find(params?: ServiceParams): Promise<Paginated<Result> | Result[]>
167167
async _find(params: ServiceParams = {} as ServiceParams): Promise<Paginated<Result> | Result[]> {
168168
const { filters, paginate } = this.filterQuery(params)
169-
const { name, id } = this.getOptions(params)
169+
const { Model, name, id } = this.getOptions(params)
170170
const builder = params.knex ? params.knex.clone() : this.createQuery(params)
171-
const countBuilder = builder.clone().clearSelect().clearOrder().count(`${name}.${id} as total`)
172-
171+
const countBuilder = Model.count(`* as total`)
172+
.with('subquery', builder.clone().clearOrder())
173+
.from('subquery')
173174
// Handle $limit
174175
if (filters.$limit) {
175176
builder.limit(filters.$limit)

0 commit comments

Comments
 (0)