Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joins Not Working with Paginator #83

Open
steveroseik opened this issue Feb 14, 2024 · 2 comments
Open

Joins Not Working with Paginator #83

steveroseik opened this issue Feb 14, 2024 · 2 comments

Comments

@steveroseik
Copy link

steveroseik commented Feb 14, 2024

this is a normal query join that works fine:

const res = await this.repo.createQueryBuilder('courierSheet') .leftJoinAndSelect('courierSheet.sheetOrders', 'sheetOrders').execute();

This is paginator code:

` const queryBuilder = this.repo.createQueryBuilder('courierSheet')
.leftJoinAndSelect('courierSheet.sheetOrders', 'sheetOrders');

const paginator = buildPaginator({
  entity: CourierSheet,
  paginationKeys: ['id'],
  query: {
    limit: input.limit,
    order: input.isAsc ? 'ASC' : 'DESC',
    beforeCursor: input.beforeCursor,
    afterCursor: input.afterCursor
  }
})
return paginator.paginate(queryBuilder);`

when I try to execute it with paginator I get error:

`TypeORMError: "couriersheet" alias was not found. Maybe you forgot to join it?
at QueryExpressionMap.findAliasByName (/Users/roseik/js-projects/greenline_server/src/query-builder/QueryExpressionMap.ts:448:19)
at /Users/roseik/js-projects/greenline_server/src/query-builder/SelectQueryBuilder.ts:3674:54
at Array.map (<anonymous>)
at SelectQueryBuilder.createOrderByCombinedWithSelectExpression (/Users/roseik/js-projects/greenline_server/src/query-builder/SelectQueryBuilder.ts:3669:14)
at SelectQueryBuilder.executeEntitiesAndRawResults (/Users/roseik/js-projects/greenline_server/src/query-builder/SelectQueryBuilder.ts:3429:22)
at SelectQueryBuilder.getRawAndEntities (/Users/roseik/js-projects/greenline_server/src/query-builder/SelectQueryBuilder.ts:1670:40)
at SelectQueryBuilder.getMany (/Users/roseik/js-projects/greenline_server/src/query-builder/SelectQueryBuilder.ts:1760:36)
at Paginator.<anonymous> (/Users/roseik/js-projects/greenline_server/node_modules/typeorm-cursor-pagination/src/Paginator.ts:81:60)
at Generator.next (<anonymous>)
at /Users/roseik/js-projects/greenline_server/node_modules/typeorm-cursor-pagination/lib/Paginator.js:8:71`
@Avetik666
Copy link

I think the issue is not with the join but rather with the fact that courierSheet is used as couriersheet so it automatically does toLowerCase() I think which breaks the query. I have the exact same issue

@Avetik666
Copy link

Avetik666 commented Mar 13, 2024

Found the solution

const paginator = buildPaginator({
entity: CourierSheet,
alias: 'courierSheet',
paginationKeys: ['id'],
query: {
limit: input.limit,
order: input.isAsc ? 'ASC' : 'DESC',
beforeCursor: input.beforeCursor,
afterCursor: input.afterCursor
}
})

just add the alias and it will work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants