Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Buffer in primary columns causes bugs with relations (#7952)
* fixed using Buffer in relations * removed console.log * added test for #4060
- Loading branch information
1 parent
29f1f86
commit 37e08a7
Showing
9 changed files
with
88 additions
and
25 deletions.
There are no files selected for viewing
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
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
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
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
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,15 @@ | ||
import {Column, Entity, JoinColumn, OneToOne, PrimaryColumn} from "../../../../src"; | ||
import {Foo} from "./Foo"; | ||
|
||
@Entity() | ||
export class Bar { | ||
@PrimaryColumn({ type: "varbinary", length: 16 }) | ||
id: Buffer; | ||
|
||
@Column() | ||
name: string; | ||
|
||
@OneToOne(() => Foo) | ||
@JoinColumn({ name: "id", referencedColumnName: "id" }) | ||
foo: Foo; | ||
} |
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,10 @@ | ||
import {Column, Entity, PrimaryColumn} from "../../../../src"; | ||
|
||
@Entity() | ||
export class Foo { | ||
@PrimaryColumn({ type: "varbinary", length: 16 }) | ||
id: Buffer; | ||
|
||
@Column() | ||
name: string; | ||
} |
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,36 @@ | ||
import { expect } from "chai"; | ||
import { Connection } from "../../../src"; | ||
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import {Foo} from "./entity/Foo"; | ||
import {Bar} from "./entity/Bar"; | ||
|
||
describe("github issues > #4060 Fail to insert entity with Buffer type of primary column under some circumstances.", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => { | ||
connections = await createTestingConnections({ | ||
enabledDrivers: ["mysql", "mariadb"], | ||
entities: [Foo, Bar], | ||
schemaCreate: true, | ||
dropSchema: true | ||
}); | ||
}); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should save entities", () => Promise.all(connections.map(async connection => { | ||
const id = Buffer.from("foobar"); | ||
const foo = new Foo(); | ||
foo.id = id; | ||
foo.name = "foo"; | ||
await connection.manager.save(foo); | ||
|
||
const bar = new Bar(); | ||
bar.id = id; | ||
bar.name = "bar"; | ||
await connection.manager.save(bar); | ||
|
||
expect(foo).to.exist; | ||
expect(bar).to.exist; | ||
}))); | ||
}); |
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
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