Repository navigation
Description
Issue Description
RelationIdLoader class is doing selects, but it's not using DriverUtils.buildAlias so the selects can end up being truncated and all related behaviour is broken. This for example breaks relationLoadStrategy: 'query' when the relation key ends up being too long.
Expected Behavior
RelationIdLoader should use DriverUtils.buildAlias when creating column aliases generating column aliases that fit the maxAliasLength prop of driver.
Actual Behavior
RelationIdLoader ignores maxAliasLength.
Steps to Reproduce
(in postgresql)
Schema
@Entity()
export class SuperLongTableName {
@PrimaryGeneratedColumn()
id: number
@Column()
name: string
@OneToMany(() => SuperLongTableNameWhichIsRelatedToOriginalTable, table => table.superLongTableName)
relatedToOriginal: SuperLongTableNameWhichIsRelatedToOriginalTable[]
}
@Entity()
export class SuperLongTableNameWhichIsRelatedToOriginalTable{
@PrimaryGeneratedColumn()
id: number
@Column()
superLongTableNameId: number;
@ManyToOne(() => SuperLongTableName, table => table.relatedToOriginal)
@JoinColumn({ name: 'superLongTableNameId' })
superLongTableName: SuperLongTableName
}INSERT INTO "SuperLongTableName" ("name") VALUES ('test');
INSERT INTO "SuperLongTableNameWhichIsRelatedToOriginal" ("superLongTableNameId") VALUES (1);const data = await appDataSource.getRepository(SuperLongTableName).findOne({
where: { id: 1 },
relations: { relatedToOriginal: true }
})
// data = { name: 'test', relatedToOriginal: [] }This is because RelationIdLoader will generate column with name: SuperLongTableNameWhichIsRelatedToOriginal_relatedToOriginal_superLongTableNameId which is then truncated by database and all the conditions in the code fail because of that.
Relevant issues
My Environment
| Dependency | Version |
|---|---|
| Operating System | |
| Node.js version | 14.19.1 |
| Typescript version | 4.8.2 |
| TypeORM version | 0.3.7 |
Relevant Database Driver(s)
| DB Type | Reproducible |
|---|---|
aurora-mysql |
no |
aurora-postgres |
no |
better-sqlite3 |
no |
cockroachdb |
no |
cordova |
no |
expo |
no |
mongodb |
no |
mysql |
no |
nativescript |
no |
oracle |
no |
postgres |
yes |
react-native |
no |
sap |
no |
spanner |
no |
sqlite |
no |
sqlite-abstract |
no |
sqljs |
no |
sqlserver |
no |
Are you willing to resolve this issue by submitting a Pull Request?
- ✖️ Yes, I have the time, and I know how to start.
- ✅ Yes, I have the time, but I don't know how to start. I would need guidance.
- ✖️ No, I don’t have the time, but I can support (using donations) development.
- ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
(EDIT: Fixed the example, the names were too short)
Activity
fix: RelationIdLoader is now using column alias utils
fix: RelationIdLoader is now using column alias utils
fix: Update RelationIdLoader to use DriverUtils.getAlias
fix: Update RelationIdLoader to use DriverUtils.getAlias (#9380)
depyronick commentedon Nov 21, 2022
I'm having
propertyPathundefined error while usingqueryrelations. Is this related to that? Works withjoinbut not withquery. Mysqldepyronick commentedon Nov 21, 2022
ok... it's because inverse side reference should be different than the referencedColumnName in my case
depyronick commentedon Nov 26, 2022
but seriously, any chance this should cause problems?