benjamin658 / typeorm-cursor-pagination

Cursor-based pagination works with TypeORM Query Builder.
MIT License
186 stars 40 forks source link

QueryFailedError: missing FROM-clause entry for table #61

Closed boukmi closed 2 years ago

boukmi commented 2 years ago

Hi,

I'm getting the following error when I try to implement pagination for one of my TypeORM entities: QueryFailedError: missing FROM-clause entry for table "typeormworker"

@Entity('worker')
export class TypeOrmWorker extends AbstractOrmEntity {
  @Column({ name: 'first_name' })
  firstName: string;

  @Column({ name: 'last_name' })
  lastName: string;

  @Column({ unique: true })
  email: string;

  @Column()
  phone: string;

  @Column({ name: 'date_of_birth', type: 'date' })
  dateOfBirth: Date;
}

And the repository:

public async findAll(): Promise<void> {
    const queryBuilder: SelectQueryBuilder<TypeOrmWorker> =
      this.createQueryBuilder('worker');

    const paginator: Paginator<TypeOrmWorker> = buildPaginator<TypeOrmWorker>({
      entity: TypeOrmWorker,
      paginationKeys: ['id'],
      query: {
        limit: 10,
        order: Order.ASC,
      },
    });

    const { data, cursor } = await paginator.paginate(queryBuilder.clone());
    console.log('data', data);
    console.log('cursor', cursor);
  }

Any idea why I'm getting this error?

Thank you so much.

benjamin658 commented 2 years ago

This is not a paginator issue, please try

    const queryBuilder: SelectQueryBuilder<TypeOrmWorker> =
      this.createQueryBuilder(TypeOrmWorker, 'worker');