Skip to content

RelationIdLoader is not consistently respecting maxAliasLength #11227

Closed

Description

@te1

Issue description

RelationIdLoader is using DriverUtils.buildAlias in some places but not in others. Notably this causes relationLoadStrategy: 'query' to fail while 'join' works for OneToOne relations that generate very long aliases.

Expected Behavior

RelationIdLoader should consistently use DriverUtils.buildAlias when generating column aliases that fit the maxAliasLength prop of driver.

Actual Behavior

loadForManyToOneAndOneToOneOwner ignores maxAliasLength for the hasAllJoinColumnsInEntity case. This causes id mismatches later in loadManyToManyRelationIdsAndGroup which uses DriverUtils.buildAlias.

Steps to reproduce

Applies to PostgreSQL, MySQL and possibly other drivers

Schema

@Entity()
export class SomeEntity {
    @PrimaryGeneratedColumn()
    id: number

    @Column()
    superLongRelatedEntityNameDontAskWhy_id: number

    @OneToOne(() => SuperLongRelatedEntityNameDontAskWhy)
    @JoinColumn({ name: "superLongRelatedEntityNameDontAskWhy_id" })
    superLongRelatedEntityNameDontAskWhy: SuperLongRelatedEntityNameDontAskWhy
}

@Entity()
export class SuperLongRelatedEntityNameDontAskWhy {
    @PrimaryGeneratedColumn()
    id: number

    @Column()
    name: string
}

Test Case

const related = await connection
    .getRepository(SuperLongRelatedEntityNameDontAskWhy)
    .save({ name: "test" })

const entity = await connection.getRepository(SomeEntity).save({
    superLongRelatedEntityNameDontAskWhy_id: related.id,
})

const result = await connection.getRepository(SomeEntity).findOne({
    where: { id: entity.id },
    relations: { superLongRelatedEntityNameDontAskWhy: true },
    relationLoadStrategy: "query",
})

// result.superLongRelatedEntityNameDontAskWhy is null

My Environment

Dependency Version
Operating System Windows 10 Pro 22H2
Node.js version 18.20.4
Typescript version 5.7.2
TypeORM version 0.3.20

Additional Context

This is a follow up to #9379 / #9380 which didn't consider this specific case.

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.

Activity

  1. github-actions commented on Sep 17, 2025

    @github-actions

    TypeORM has returned to active development after recently transitioning to new leadership (see related announcement).

    As part of the new team's efforts to prioritise work on the project moving forward, it is necessary to clean up the backlog of stale issues.

    🧹 This issue is being automatically closed because it has had no activity in the last 6 months.
    If you believe this issue is still relevant, feel free to comment below and the maintainers may reopen it. Thank you for your contribution.

  2. te1 commented on Sep 17, 2025

    @te1
    ContributorAuthor

    Still relevant. PR is linked and awaiting review (tests included).

  3. reopened this on Sep 18, 2025
  4. gioboa commented on Sep 18, 2025

    @gioboa
    Collaborator

    Thanks for the heads up @te1

  5. added this to the 1.0 milestone on Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions