Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit a3a6e06

Browse files
authored
fix: column name with empty spaces causes bug in Index/Unique decorators typeorm#7534
1 parent bc29597 commit a3a6e06

File tree

5 files changed

+13
-22
lines changed

5 files changed

+13
-22
lines changed

src/metadata/IndexMetadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class IndexMetadata {
164164
if (this.embeddedMetadata)
165165
return this.embeddedMetadata.propertyPath + "." + columnName;
166166

167-
return columnName;
167+
return columnName.trim();
168168
});
169169
columnPropertyPaths.forEach(propertyPath => map[propertyPath] = 1);
170170
} else { // todo: indices in embeds are not implemented in this syntax. deprecate this syntax?

src/metadata/UniqueMetadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class UniqueMetadata {
9898
if (this.embeddedMetadata)
9999
return this.embeddedMetadata.propertyPath + "." + columnName;
100100

101-
return columnName;
101+
return columnName.trim();
102102
});
103103
columnPropertyPaths.forEach(propertyPath => map[propertyPath] = 1);
104104
} else {

test/github-issues/6752/entity/Block.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import {
2-
Column, Entity, Index, OneToMany, PrimaryGeneratedColumn,
3-
} from "../../../../src";
4-
import { PlanOfRecord } from "./PlanOfRecord";
1+
import {Column, Entity, Index, OneToMany, PrimaryGeneratedColumn} from "../../../../src";
2+
import {PlanOfRecord} from "./PlanOfRecord";
53

6-
// @Entity({ synchronize: false })
74
@Entity({ synchronize: true })
85
@Index(["chip_name", "manual", "frequency", "mode"], { unique: true })
96
export class Block {
@@ -30,7 +27,6 @@ export class Block {
3027
@Index()
3128
public mode: string;
3229

33-
@OneToMany((type) => PlanOfRecord, (por) => por.block)
30+
@OneToMany(() => PlanOfRecord, (por) => por.block)
3431
public plan_of_records: PlanOfRecord[];
3532
}
36-

test/github-issues/6752/entity/PlanOfRecord.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import {
2-
Check, Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn,
2+
Check, Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn, Unique,
33
} from "../../../../src";
44
import { Block } from "./Block";
55

6-
// @Entity({ synchronize: false })
76
@Entity({ synchronize: true })
87
@Index(["block", "softwareComponent", "module", "module_sku ", "isSafety"], { unique: true })
9-
// Enable sync will sometimes cause planOfRecord column become null
8+
@Unique(["block", "softwareComponent", "module", "module_sku ", "isSafety"])
109
@Check(`"planOfRecord" IN ('NOT_POR', 'POR_BUT_PROD_VAL', 'POR_BUT_RESET_VAL')`)
1110
export class PlanOfRecord {
1211
@PrimaryGeneratedColumn()

test/github-issues/6752/issue-6752.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import "reflect-metadata";
2-
import {
3-
createTestingConnections,
4-
closeTestingConnections,
5-
reloadTestingDatabases,
6-
} from "../../utils/test-utils";
7-
import { Connection } from "../../../src/connection/Connection";
8-
import { expect } from "chai";
9-
import { Block } from "./entity/Block";
10-
import { PlanOfRecord } from "./entity/PlanOfRecord";
2+
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases,} from "../../utils/test-utils";
3+
import {Connection} from "../../../src";
4+
import {expect} from "chai";
5+
import {Block} from "./entity/Block";
6+
import {PlanOfRecord} from "./entity/PlanOfRecord";
117

12-
describe.skip("github issues > #6752 column name not been find on unique index decorator", () => {
8+
describe("github issues > #6752 column name not been find on unique index decorator", () => {
139
it("dont change anything", async () => {
1410
let connections: Connection[];
1511
connections = await createTestingConnections({

0 commit comments

Comments
 (0)