-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update RelationIdLoader to use DriverUtils.getAlias (#9380)
Update RelationIdLoader to use DriverUtils.getAlias to prevent aliases being possibly trimmed by database. Closes: #9379 Co-authored-by: Jan Zípek <jan@zipek.cz>
- Loading branch information
1 parent
6bc723b
commit a917d65
Showing
4 changed files
with
138 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
OneToMany, | ||
} from "../../../../src" | ||
import { SuperLongTableNameWhichIsRelatedToOriginalTable } from "./SuperLongTableNameIsRelatedToOriginal" | ||
|
||
@Entity() | ||
export class SuperLongTableName { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Column() | ||
name: string | ||
|
||
@OneToMany( | ||
() => SuperLongTableNameWhichIsRelatedToOriginalTable, | ||
(table) => table.superLongTableName, | ||
) | ||
relatedToOriginal: SuperLongTableNameWhichIsRelatedToOriginalTable[] | ||
} |
21 changes: 21 additions & 0 deletions
21
test/github-issues/9379/entity/SuperLongTableNameIsRelatedToOriginal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
ManyToOne, | ||
JoinColumn, | ||
} from "../../../../src" | ||
import { SuperLongTableName } from "./SuperLongTableName" | ||
|
||
@Entity() | ||
export class SuperLongTableNameWhichIsRelatedToOriginalTable { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Column() | ||
superLongTableNameId: number | ||
|
||
@ManyToOne(() => SuperLongTableName, (table) => table.relatedToOriginal) | ||
@JoinColumn({ name: "superLongTableNameId" }) | ||
superLongTableName: SuperLongTableName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import "reflect-metadata" | ||
import { expect } from "chai" | ||
import { DataSource } from "../../../src/data-source/DataSource" | ||
import { | ||
closeTestingConnections, | ||
createTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils" | ||
import { SuperLongTableName } from "./entity/SuperLongTableName" | ||
import { SuperLongTableNameWhichIsRelatedToOriginalTable } from "./entity/SuperLongTableNameIsRelatedToOriginal" | ||
|
||
describe.only("github issues > #9379 RelationIdLoader is not respecting maxAliasLength", () => { | ||
let connections: DataSource[] | ||
before( | ||
async () => | ||
(connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["postgres"], | ||
})), | ||
) | ||
beforeEach(() => reloadTestingDatabases(connections)) | ||
after(() => closeTestingConnections(connections)) | ||
|
||
it("should fetch related entities properly", async () => { | ||
for (const connection of connections) { | ||
const origin = await connection | ||
.getRepository(SuperLongTableName) | ||
.save({ name: "test" }) | ||
|
||
await connection | ||
.getRepository(SuperLongTableNameWhichIsRelatedToOriginalTable) | ||
.save({ | ||
superLongTableNameId: origin.id, | ||
}) | ||
|
||
const result = await connection | ||
.getRepository(SuperLongTableName) | ||
.findOne({ | ||
where: { id: origin.id }, | ||
relations: { relatedToOriginal: true }, | ||
relationLoadStrategy: "query", | ||
}) | ||
|
||
expect(result?.relatedToOriginal.length).to.eq(1) | ||
} | ||
}) | ||
}) |