From 3cf470d92a543830569dd4a6bd62882ec22cc656 Mon Sep 17 00:00:00 2001 From: Aviad Hadad Date: Thu, 5 Sep 2019 18:46:19 +0300 Subject: [PATCH] fix: change PrimaryColumn decorator to clone passed options (#4571) Closes: #4570 --- src/decorator/columns/PrimaryColumn.ts | 2 +- test/github-issues/4570/issue-4570.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/github-issues/4570/issue-4570.ts diff --git a/src/decorator/columns/PrimaryColumn.ts b/src/decorator/columns/PrimaryColumn.ts index 3d479a9faf..9c56828bf6 100644 --- a/src/decorator/columns/PrimaryColumn.ts +++ b/src/decorator/columns/PrimaryColumn.ts @@ -31,7 +31,7 @@ export function PrimaryColumn(typeOrOptions?: ColumnType|ColumnOptions, options? if (typeof typeOrOptions === "string") { type = typeOrOptions; } else { - options = typeOrOptions; + options = Object.assign({}, typeOrOptions); } if (!options) options = {} as ColumnOptions; diff --git a/test/github-issues/4570/issue-4570.ts b/test/github-issues/4570/issue-4570.ts new file mode 100644 index 0000000000..e2ae7b3415 --- /dev/null +++ b/test/github-issues/4570/issue-4570.ts @@ -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); + }); +});