-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4124 from EctorParking/fix/relation-alias
Allow join relation alias override from naming strategies
- Loading branch information
Showing
7 changed files
with
69 additions
and
1 deletion.
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
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,15 @@ | ||
import {Entity, PrimaryGeneratedColumn, ManyToOne, JoinColumn} from "../../../../src/index"; | ||
import { Contact } from "./Contact"; | ||
|
||
@Entity() | ||
export class Booking { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@ManyToOne(type => Contact, contact => contact.bookings, { eager: true }) | ||
@JoinColumn({ | ||
name: "contact_id", | ||
}) | ||
contact: Contact; | ||
} |
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,12 @@ | ||
import {Entity, PrimaryGeneratedColumn, OneToMany} from "../../../../src/index"; | ||
import { Booking } from "./Booking"; | ||
|
||
@Entity() | ||
export class Contact { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@OneToMany(type => Booking, booking => booking.contact) | ||
bookings: Booking[]; | ||
} |
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,27 @@ | ||
import "reflect-metadata"; | ||
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils"; | ||
import {Connection} from "../../../src/connection/Connection"; | ||
import {Booking} from "./entity/Booking"; | ||
import {NamingStrategyUnderTest} from "./naming/NamingStrategyUnderTest"; | ||
|
||
|
||
describe("github issue > #2200 Bug - Issue with snake_case naming strategy", () => { | ||
|
||
let connections: Connection[]; | ||
let namingStrategy = new NamingStrategyUnderTest(); | ||
|
||
before(async () => connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
namingStrategy | ||
})); | ||
beforeEach(() => { | ||
return reloadTestingDatabases(connections); | ||
}); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
|
||
it("Renammed alias allow to query correctly", () => Promise.all(connections.map(async connection => { | ||
await connection.getRepository(Booking).find({take: 10}); | ||
}))); | ||
|
||
}); |
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,7 @@ | ||
import { DefaultNamingStrategy } from "../../../../src/naming-strategy/DefaultNamingStrategy"; | ||
import { NamingStrategyInterface } from "../../../../src/naming-strategy/NamingStrategyInterface"; | ||
|
||
export class NamingStrategyUnderTest extends DefaultNamingStrategy implements NamingStrategyInterface { | ||
eagerJoinRelationAlias(alias: string, propertyPath: string): string { | ||
return alias + "__" + propertyPath.replace(".", "_"); | ||
}} |