Repository navigation
Closed
Description
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 nullMy 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
github-actions commentedon Sep 17, 2025
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.
te1 commentedon Sep 17, 2025
Still relevant. PR is linked and awaiting review (tests included).
gioboa commentedon Sep 18, 2025
Thanks for the heads up @te1