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

Commit

Permalink
fix: change PrimaryColumn decorator to clone passed options (typeorm#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sthuck authored and pleerock committed Sep 5, 2019
1 parent 9e3d664 commit 3cf470d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/decorator/columns/PrimaryColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function PrimaryColumn(typeOrOptions?: ColumnType|ColumnOptions, options?
if (typeof typeOrOptions === "string") {
type = <ColumnType> typeOrOptions;
} else {
options = <ColumnOptions> typeOrOptions;
options = Object.assign({}, <ColumnOptions> typeOrOptions);
}
if (!options) options = {} as ColumnOptions;

Expand Down
19 changes: 19 additions & 0 deletions test/github-issues/4570/issue-4570.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import "reflect-metadata";

import {expect} from "chai";
import {ColumnOptions, PrimaryColumn} from "../../../src";

describe("github issues > #4570 Fix PrimaryColumn decorator modifies passed option", () => {
it("should not modify passed options to PrimaryColumn", () => {
const options: ColumnOptions = {type: "varchar" };
const clone = Object.assign({}, options);

class Entity {
@PrimaryColumn(options)
pkey: string;
}

expect(Entity).to.be;
expect(clone).to.be.eql(options);
});
});

0 comments on commit 3cf470d

Please sign in to comment.