-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: confirm finding by a relation with a composite key works (#8052)
Co-authored-by: vlastv <me@vlastv.ru>
- Loading branch information
1 parent
fe78bee
commit ba366f2
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
test/functional/query-builder/composite-primary/composite-primary.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
test/functional/query-builder/composite-primary/entity/Bar.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
test/functional/query-builder/composite-primary/entity/Foo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |