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

SelectQueryBuilder error when using subqueries and pagination #10814

Open
1 of 18 tasks
nikolay-rogovoy opened this issue Apr 4, 2024 · 0 comments
Open
1 of 18 tasks

SelectQueryBuilder error when using subqueries and pagination #10814

nikolay-rogovoy opened this issue Apr 4, 2024 · 0 comments

Comments

@nikolay-rogovoy
Copy link

nikolay-rogovoy commented Apr 4, 2024

Issue description

When I use subqueries and pagination I get the error Cannot get entity metadata for the given alias ...

Expected Behavior

List of entities

Actual Behavior

TypeORMError: Cannot get entity metadata for the given alias ....

Steps to reproduce

`@Entity()
export class T1 {

@PrimaryGeneratedColumn()
id: number

@Column({
    nullable: true
})
name: string;

@OneToMany(type => T2, t2 => t2.t1)
t2s: T2[];

}
`

`
@entity()
export class T2 {

@PrimaryGeneratedColumn()
id: number

@Column({
    nullable: true
})
name: string;

@ManyToOne(() => T1)
@JoinColumn({ name: 'idt1' })
t1?: T1;

}`

let qb = this.dataSource.createQueryBuilder()
  .select('t2')
  .from(T2, 't2')
  .innerJoin((subquery: SelectQueryBuilder<T1>) => {
    return subquery.
      select('t1.id', 'id')
      .addSelect('t1.name', 'name')
      .from(T1 , 't1');
  }, 's', 't2.idt1 = s.id')
  .orderBy('s.name')
  .take(10).skip(0);

const data = await qb.getManyAndCount();

Without take(10).skip(0) everything works fine.
I know that t1 can be added without a subquery.
This example is for demonstration purposes.

My Environment

Typeorm: 0.3.20
Operating System: Linix
Node.js version: 18.17.1
Typescript version: 5.1.3

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, and I know how to start.

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

No branches or pull requests

1 participant