-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Only check for discriminator conflicts on STI entities (#2985)
If an entity has the same discriminator value as one using `TableInheritance` this should be allowed as there is no way for them to conflict. This commit also fixes the discriminatorColumn check to check all the entities it should be checking. Only the parent in an STI setup has the "STI" inheritancePattern, the children just have the "entity-child" tableType. Before two children with the same discriminatorValue would be (incorrectly) allowed as they'd never even get checked. Fixes #2984
- Loading branch information
Showing
7 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {Entity, PrimaryGeneratedColumn} from "../../../../../src"; | ||
|
||
@Entity({name: "commitNote"}) | ||
export class Note { | ||
|
||
@PrimaryGeneratedColumn() | ||
public id: number; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {Entity, PrimaryGeneratedColumn, TableInheritance} from "../../../../../src"; | ||
|
||
@Entity({name: "issueNote"}) | ||
@TableInheritance({column: {type: "varchar", name: "type"}}) | ||
export class Note { | ||
|
||
@PrimaryGeneratedColumn() | ||
public id: number; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {ChildEntity, Column} from "../../../../../src"; | ||
import {Note} from "./note"; | ||
|
||
@ChildEntity() | ||
export class OwnerNote extends Note { | ||
|
||
@Column() | ||
public owner: string; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {Entity, PrimaryGeneratedColumn, TableInheritance} from "../../../../../src"; | ||
|
||
@Entity({name: "wikiNote"}) | ||
@TableInheritance({column: {type: "varchar", name: "type"}}) | ||
export class Note { | ||
|
||
@PrimaryGeneratedColumn() | ||
public id: number; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {ChildEntity, Column} from "../../../../../src"; | ||
import {Note} from "./note"; | ||
|
||
@ChildEntity() | ||
export class OwnerNote extends Note { | ||
|
||
@Column() | ||
public owner: string; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import "reflect-metadata"; | ||
|
||
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils"; | ||
import {Connection} from "../../../src"; | ||
|
||
describe("github issues > #2984 Discriminator conflict reported even for non-inherited tables", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/**/*{.js,.ts}"], | ||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should load entities even with the same discriminator", () => Promise.all(connections.map(async connection => { | ||
connection.entityMetadatas.should.have.length(5); | ||
connection.entityMetadatas.forEach(metadata => | ||
metadata.discriminatorValue!.should.be.oneOf(["Note", "OwnerNote"])); | ||
}))); | ||
|
||
}); |