Skip to content

Commit

Permalink
fix: column name with empty spaces causes bug in Index/Unique decorat…
Browse files Browse the repository at this point in the history
…ors #7534
  • Loading branch information
AlexMesser committed Apr 10, 2021
1 parent bc29597 commit a3a6e06
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/metadata/IndexMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class IndexMetadata {
if (this.embeddedMetadata)
return this.embeddedMetadata.propertyPath + "." + columnName;

return columnName;
return columnName.trim();
});
columnPropertyPaths.forEach(propertyPath => map[propertyPath] = 1);
} else { // todo: indices in embeds are not implemented in this syntax. deprecate this syntax?
Expand Down
2 changes: 1 addition & 1 deletion src/metadata/UniqueMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class UniqueMetadata {
if (this.embeddedMetadata)
return this.embeddedMetadata.propertyPath + "." + columnName;

return columnName;
return columnName.trim();
});
columnPropertyPaths.forEach(propertyPath => map[propertyPath] = 1);
} else {
Expand Down
10 changes: 3 additions & 7 deletions test/github-issues/6752/entity/Block.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {
Column, Entity, Index, OneToMany, PrimaryGeneratedColumn,
} from "../../../../src";
import { PlanOfRecord } from "./PlanOfRecord";
import {Column, Entity, Index, OneToMany, PrimaryGeneratedColumn} from "../../../../src";
import {PlanOfRecord} from "./PlanOfRecord";

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

@OneToMany((type) => PlanOfRecord, (por) => por.block)
@OneToMany(() => PlanOfRecord, (por) => por.block)
public plan_of_records: PlanOfRecord[];
}

5 changes: 2 additions & 3 deletions test/github-issues/6752/entity/PlanOfRecord.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {
Check, Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn,
Check, Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn, Unique,
} from "../../../../src";
import { Block } from "./Block";

// @Entity({ synchronize: false })
@Entity({ synchronize: true })
@Index(["block", "softwareComponent", "module", "module_sku ", "isSafety"], { unique: true })
// Enable sync will sometimes cause planOfRecord column become null
@Unique(["block", "softwareComponent", "module", "module_sku ", "isSafety"])
@Check(`"planOfRecord" IN ('NOT_POR', 'POR_BUT_PROD_VAL', 'POR_BUT_RESET_VAL')`)
export class PlanOfRecord {
@PrimaryGeneratedColumn()
Expand Down
16 changes: 6 additions & 10 deletions test/github-issues/6752/issue-6752.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import "reflect-metadata";
import {
createTestingConnections,
closeTestingConnections,
reloadTestingDatabases,
} from "../../utils/test-utils";
import { Connection } from "../../../src/connection/Connection";
import { expect } from "chai";
import { Block } from "./entity/Block";
import { PlanOfRecord } from "./entity/PlanOfRecord";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases,} from "../../utils/test-utils";
import {Connection} from "../../../src";
import {expect} from "chai";
import {Block} from "./entity/Block";
import {PlanOfRecord} from "./entity/PlanOfRecord";

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

0 comments on commit a3a6e06

Please sign in to comment.