mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
* test: create simplified test for https://github.com/typeorm/typeorm/issues/8018 * test: improve test title for issue 8018 to be consistent with project Co-authored-by: cduff <chris@praxhub.com>
This commit is contained in:
parent
0adad8810e
commit
bc55836fff
24
test/github-issues/8018/entity/Child.ts
Normal file
24
test/github-issues/8018/entity/Child.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from "../../../../src";
|
||||
import { Grandchild } from "./Grandchild";
|
||||
import { Parent } from "./Parent";
|
||||
|
||||
@Entity()
|
||||
export class Child {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
name?: string;
|
||||
|
||||
@ManyToOne(() => Parent, (parent) => parent.children)
|
||||
parent?: Parent;
|
||||
|
||||
@OneToMany(() => Grandchild, (grandchild) => grandchild.parent)
|
||||
children?: Grandchild[];
|
||||
}
|
||||
11
test/github-issues/8018/entity/Grandchild.ts
Normal file
11
test/github-issues/8018/entity/Grandchild.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Entity, ManyToOne, PrimaryGeneratedColumn } from "../../../../src";
|
||||
import { Child } from "./Child";
|
||||
|
||||
@Entity()
|
||||
export class Grandchild {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@ManyToOne(() => Child, (parent) => parent.children)
|
||||
parent?: Child;
|
||||
}
|
||||
19
test/github-issues/8018/entity/Parent.ts
Normal file
19
test/github-issues/8018/entity/Parent.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from "../../../../src";
|
||||
import { Child } from "./Child";
|
||||
|
||||
@Entity()
|
||||
export class Parent {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
name?: string;
|
||||
|
||||
@OneToMany(() => Child, (child) => child.parent)
|
||||
children?: Child[];
|
||||
}
|
||||
52
test/github-issues/8018/issue-8018.ts
Normal file
52
test/github-issues/8018/issue-8018.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { expect } from "chai";
|
||||
import "reflect-metadata";
|
||||
import { Connection } from "../../../src";
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
} from "../../utils/test-utils";
|
||||
import { Child } from "./entity/Child";
|
||||
import { Grandchild } from "./entity/Grandchild";
|
||||
import { Parent } from "./entity/Parent";
|
||||
|
||||
describe("github issues > #8018 Non-unique relation property names causes entity mixup in query results", () => {
|
||||
let connections: Connection[];
|
||||
before(
|
||||
async () =>
|
||||
(connections = await createTestingConnections({
|
||||
entities: [Parent, Child, Grandchild],
|
||||
schemaCreate: true,
|
||||
dropSchema: true,
|
||||
}))
|
||||
);
|
||||
beforeEach(async () => await reloadTestingDatabases(connections));
|
||||
after(() => closeTestingConnections(connections));
|
||||
|
||||
it("should create child entities of the correct type", async () =>
|
||||
await Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
const parent = new Parent();
|
||||
parent.name = "parent";
|
||||
|
||||
const child1 = new Child();
|
||||
child1.name = "child1";
|
||||
child1.parent = parent;
|
||||
|
||||
const child2 = new Child();
|
||||
child2.name = "child2";
|
||||
child2.parent = parent;
|
||||
|
||||
await connection.manager.save([parent, child1, child2]);
|
||||
|
||||
const result = await connection.manager.find(Parent, {
|
||||
relations: ["children"],
|
||||
});
|
||||
|
||||
expect(result).to.have.lengthOf(1);
|
||||
expect(result[0].children).to.have.lengthOf(2);
|
||||
expect(result[0].children![0]).to.be.instanceOf(Child);
|
||||
expect(result[0].children![1]).to.be.instanceOf(Child);
|
||||
})
|
||||
));
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user