mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
added test for nested child entities
This commit is contained in:
parent
cd06738911
commit
f3ce25acfa
@ -0,0 +1,10 @@
|
||||
import {ChildEntity} from "../../../../src/index";
|
||||
|
||||
import {Tournament} from "./Tournament";
|
||||
|
||||
@ChildEntity() // Causes Error of duplicated column in generated sql
|
||||
export class BilliardsTournament extends Tournament {
|
||||
constructor(billiardsTournament?: {name: string}) {
|
||||
super(billiardsTournament);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
import {ChildEntity} from "../../../../src/index";
|
||||
|
||||
import {BilliardsTournament} from "./BilliardsTournament";
|
||||
|
||||
@ChildEntity()
|
||||
export class SquadBilliardsTournament extends BilliardsTournament {
|
||||
constructor(squadBilliardsTournament?: {name: string}) {
|
||||
super(squadBilliardsTournament);
|
||||
}
|
||||
}
|
||||
29
test/other-issues/nested-child-entities/entity/Tournament.ts
Normal file
29
test/other-issues/nested-child-entities/entity/Tournament.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import {TableInheritance, Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn} from "../../../../src/index";
|
||||
|
||||
import {TournamentGraph} from "./TournamentGraph";
|
||||
|
||||
@Entity()
|
||||
@TableInheritance({
|
||||
pattern: "STI",
|
||||
column: {
|
||||
name: "type",
|
||||
type: "varchar",
|
||||
},
|
||||
})
|
||||
export abstract class Tournament {
|
||||
@PrimaryGeneratedColumn()
|
||||
public id: number;
|
||||
|
||||
@Column()
|
||||
public name: string;
|
||||
|
||||
@OneToOne(type => TournamentGraph, graph => graph.tournament)
|
||||
@JoinColumn()
|
||||
public graph: TournamentGraph;
|
||||
|
||||
constructor(tournament?: {name: string}) {
|
||||
if (tournament) {
|
||||
this.name = tournament.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
import {Entity, PrimaryGeneratedColumn, OneToOne} from "../../../../src/index";
|
||||
|
||||
import {Tournament} from "./Tournament";
|
||||
|
||||
@Entity()
|
||||
export class TournamentGraph {
|
||||
@PrimaryGeneratedColumn()
|
||||
public id: number;
|
||||
|
||||
@OneToOne(type => Tournament, tournament => tournament.graph)
|
||||
public tournament: Tournament;
|
||||
}
|
||||
30
test/other-issues/nested-child-entities/issue.ts
Normal file
30
test/other-issues/nested-child-entities/issue.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
|
||||
import {Connection} from "../../../src";
|
||||
|
||||
import {TournamentGraph} from "./entity/TournamentGraph";
|
||||
import {SquadBilliardsTournament} from "./entity/SquadBilliardsTournament";
|
||||
|
||||
describe("other issues > using nested child entities", () => {
|
||||
let connections: Connection[];
|
||||
|
||||
before(async () => connections = await createTestingConnections({
|
||||
entities: [__dirname + "/entity/*{.js,.ts}"],
|
||||
}));
|
||||
|
||||
beforeEach(() => reloadTestingDatabases(connections));
|
||||
|
||||
after(() => closeTestingConnections(connections));
|
||||
|
||||
it("should insert without error", () => Promise.all(connections.map(async connection => {
|
||||
const squadBilliardsTournament = new SquadBilliardsTournament({
|
||||
name: "Squad Tournament",
|
||||
});
|
||||
|
||||
await connection.manager.save(squadBilliardsTournament);
|
||||
const tournamentGraph = new TournamentGraph();
|
||||
|
||||
tournamentGraph.tournament = squadBilliardsTournament;
|
||||
|
||||
await connection.manager.save(tournamentGraph);
|
||||
})));
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user