Skip to content

Commit

Permalink
test: confirm finding by a relation with a composite key works (#8052)
Browse files Browse the repository at this point in the history
Co-authored-by: vlastv <me@vlastv.ru>
  • Loading branch information
imnotjames and vlastv committed Aug 8, 2021
1 parent fe78bee commit ba366f2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import "reflect-metadata";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src";
import {Foo} from "./entity/Foo";
import {Bar} from "./entity/Bar";
import {expect} from "chai";

describe("query builder > composite primary", () => {

let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [ Foo, Bar ],
enabledDrivers: ["postgres"]
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));

it("should find entity by another entity with a composite key", () => Promise.all(connections.map(async connection => {
const foo = new Foo();
foo.id1 = 1
foo.id2 = 2;
await connection.manager.save(foo)

const bar = new Bar()
bar.id = 1
bar.foo = foo
await connection.manager.save(bar)

const loadedBar = await connection.manager.getRepository(Bar).findOne({
where: {
foo
}
});

expect(loadedBar!.id).to.be.equal(bar.id);
})));
});
13 changes: 13 additions & 0 deletions test/functional/query-builder/composite-primary/entity/Bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Entity} from "../../../../../src/decorator/entity/Entity";
import { ManyToOne, PrimaryColumn } from "../../../../../src";
import { Foo } from "./Foo";

@Entity()
export class Bar {

@PrimaryColumn()
id: number;

@ManyToOne(type => Foo)
foo: Foo
}
12 changes: 12 additions & 0 deletions test/functional/query-builder/composite-primary/entity/Foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {Entity} from "../../../../../src/decorator/entity/Entity";
import { PrimaryColumn } from "../../../../../src";

@Entity()
export class Foo {

@PrimaryColumn()
id1: number;

@PrimaryColumn()
id2: number;
}

0 comments on commit ba366f2

Please sign in to comment.