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

TypeORM Update query builder use wrong table name and ignore alias #10424

Open
1 of 18 tasks
LibStake opened this issue Oct 16, 2023 · 0 comments
Open
1 of 18 tasks

TypeORM Update query builder use wrong table name and ignore alias #10424

LibStake opened this issue Oct 16, 2023 · 0 comments

Comments

@LibStake
Copy link

LibStake commented Oct 16, 2023

Issue description

QueryBuilder update function use different table name on where phrase.

Expected Behavior

Database : SQLite

Entity definition

@Entity({ name: 'inventory_material' })
export default class MaterialEntity extends BaseEntity implements EntityInterface {
    @PrimaryGeneratedColumn({ name: 'id', type: 'int' })
    public id: number;
    
    @Column({ name: 'name', type: 'varchar', length: 255, nullable: false, unique: true })
    @Length(1, 255)
    public name: string;
    
    @Column({ name: 'image_url', type: 'varchar', length: 1024, nullable: true, default: null })
    public imageUrl: string | null;
    
    public stringify(): string {
        return `${this.id}_${this.name}`;
    }
}

Note that I use custom table name instead of Entity class name

Expected query
#1 - Alias given on QueryBuilder by materialRepo.createQueryBuilder('material')

UPDATE "inventory_material" SET "name" = ? WHERE id = 28

Actual Behavior

#1 - Alias given on QueryBuilder by materialRepo.createQueryBuilder('material')

UPDATE "inventory_material" SET "name" = ? WHERE material.id = 28

#2 - Alias not given

 UPDATE "inventory_material" SET "name" = ? WHERE MaterialEntity.id = 28

Both use wrong table name on where phrase

Steps to reproduce

let qb: QueryBuilder<MaterialEntity> = this.materialRepo.createQueryBuilder().where({id: materialId});
if (dto.name !== undefined)
    qb = qb.update({name: dto.name});
await qb.execute();

My Environment

Dependency Version
Operating System Windows 11
Node.js version 18.18.0
Typescript version 5.13
TypeORM version 0.3.17

Additional Context

  • I strongly suspect that problem with SQLIte table name alias and there are problem with custom table name on entity definition on SQLite too.

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?

No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

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