|
| 1 | +import "reflect-metadata" |
| 2 | +import { |
| 3 | + createTestingConnections, |
| 4 | + closeTestingConnections, |
| 5 | + reloadTestingDatabases, |
| 6 | +} from "../../utils/test-utils" |
| 7 | +import { DataSource } from "../../../src/data-source/DataSource" |
| 8 | +import { expect } from "chai" |
| 9 | +import { A } from "./entity/A" |
| 10 | +import { B } from "./entity/B" |
| 11 | +import { C } from "./entity/C" |
| 12 | + |
| 13 | +describe("github issues > #9944 Alias Issue With Nested Entity And Relations", () => { |
| 14 | + let dataSources: DataSource[] |
| 15 | + before( |
| 16 | + async () => |
| 17 | + (dataSources = await createTestingConnections({ |
| 18 | + entities: [__dirname + "/entity/*{.js,.ts}"], |
| 19 | + schemaCreate: true, |
| 20 | + dropSchema: true, |
| 21 | + relationLoadStrategy: "query", |
| 22 | + enabledDrivers: ["mysql", "postgres"], |
| 23 | + })), |
| 24 | + ) |
| 25 | + beforeEach(() => reloadTestingDatabases(dataSources)) |
| 26 | + after(() => closeTestingConnections(dataSources)) |
| 27 | + |
| 28 | + it("Validate correct loading of eager, nested relations", () => |
| 29 | + Promise.all( |
| 30 | + dataSources.map(async (dataSource) => { |
| 31 | + const aEntity = new A() |
| 32 | + aEntity.b = new B() |
| 33 | + aEntity.b.cs = [new C()] |
| 34 | + await dataSource.manager.save(aEntity) |
| 35 | + |
| 36 | + const [fetchedA] = await dataSource.manager.find(A) |
| 37 | + expect(fetchedA.b).exist // Validates correct relation A.b is loaded |
| 38 | + expect(fetchedA.b.cs).exist // Validates correct relation A.b.cs is loaded |
| 39 | + expect(fetchedA.b.cs[0]).exist |
| 40 | + }), |
| 41 | + )) |
| 42 | +}) |
0 commit comments