added test for nested child entities

This commit is contained in:
Jan Grądzki 2018-04-24 15:44:13 +02:00
parent cd06738911
commit f3ce25acfa
5 changed files with 91 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View 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;
}
}
}

View File

@ -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;
}

View 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);
})));
});