Skip to content
This repository was archived by the owner on Mar 18, 2022. It is now read-only.

Commit 3cf470d

Browse files
sthuckpleerock
authored andcommitted
fix: change PrimaryColumn decorator to clone passed options (typeorm#4571)
Closes: typeorm#4570
1 parent 9e3d664 commit 3cf470d

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/decorator/columns/PrimaryColumn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function PrimaryColumn(typeOrOptions?: ColumnType|ColumnOptions, options?
3131
if (typeof typeOrOptions === "string") {
3232
type = <ColumnType> typeOrOptions;
3333
} else {
34-
options = <ColumnOptions> typeOrOptions;
34+
options = Object.assign({}, <ColumnOptions> typeOrOptions);
3535
}
3636
if (!options) options = {} as ColumnOptions;
3737

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import "reflect-metadata";
2+
3+
import {expect} from "chai";
4+
import {ColumnOptions, PrimaryColumn} from "../../../src";
5+
6+
describe("github issues > #4570 Fix PrimaryColumn decorator modifies passed option", () => {
7+
it("should not modify passed options to PrimaryColumn", () => {
8+
const options: ColumnOptions = {type: "varchar" };
9+
const clone = Object.assign({}, options);
10+
11+
class Entity {
12+
@PrimaryColumn(options)
13+
pkey: string;
14+
}
15+
16+
expect(Entity).to.be;
17+
expect(clone).to.be.eql(options);
18+
});
19+
});

0 commit comments

Comments
 (0)