nestjsx / nestjs-typeorm-paginate

:page_with_curl: Pagination response object function + types for typeorm + nestjs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wrong itemCount

qkrwnsgh1288 opened this issue · comments

스크린샷 2021-07-28 오후 1 59 31

I set the number of items per page to 50, but 18 is the output.
I guess, it seems to count the internal array length caused by Join.
I don't want to count internal array length(thingSensors) together.

thing.service.ts

const things = await this.thingRepo
        .createQueryBuilder('thing')
        .leftJoin('thing.thingSensors', 'thingSensors')
        .select(['thing.thingId', 'thingSensors']);
      return paginate<Thing>(things, options);

thing.entity.ts

@OneToMany(() => ThingSensor, (thingSensor) => thingSensor.thing)
  thingSensors: ThingSensor[];

Ah so, from your query you're querying thing instead you should be querying thingSensors and do a left join on the thing table. This way round you'll end up counting the thing table and not the thingSensors table.