Skip to content

Commit

Permalink
feat: add constraintName to JoinColumn
Browse files Browse the repository at this point in the history
Add a constraintName to JoinColumn decorators to allow specifying foreignKey name.
Use constraintName when building JoinTable entities as well.

Partially solves: typeorm#1355
  • Loading branch information
M-TGH committed Mar 29, 2022
1 parent bf4466b commit 487ceb4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/metadata-builder/JunctionEntityMetadataBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,10 @@ export class JunctionEntityMetadataBuilder {
options: {
length:
!inverseReferencedColumn.length &&
(DriverUtils.isMySQLFamily(
this.connection.driver,
) ||
this.connection.driver.options.type ===
"aurora-mysql") &&
(this.connection.driver instanceof
MysqlDriver ||
this.connection.driver instanceof
AuroraDataApiDriver) &&
(inverseReferencedColumn.generationStrategy ===
"uuid" ||
inverseReferencedColumn.type === "uuid")
Expand Down Expand Up @@ -219,7 +218,7 @@ export class JunctionEntityMetadataBuilder {
referencedColumns: referencedColumns,
onDelete: relation.onDelete || "CASCADE",
onUpdate:
this.connection.driver.options.type === "oracle"
this.connection.driver instanceof OracleDriver
? "NO ACTION"
: relation.onUpdate || "CASCADE",
}),
Expand All @@ -233,7 +232,7 @@ export class JunctionEntityMetadataBuilder {
? relation.inverseRelation.onDelete
: "CASCADE",
onUpdate:
this.connection.driver.options.type === "oracle"
this.connection.driver instanceof OracleDriver
? "NO ACTION"
: relation.inverseRelation
? relation.inverseRelation.onUpdate
Expand Down
5 changes: 5 additions & 0 deletions src/metadata/ColumnMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ export class ColumnMetadata {
*/
constraintName?: string

/**
* If this column is foreign key then this specifies the name for it.
*/
constraintName?: string

/**
* Specifies a value transformer that is to be used to (un)marshal
* this column when reading or writing to the database.
Expand Down
5 changes: 5 additions & 0 deletions src/metadata/ForeignKeyMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export class ForeignKeyMetadata {
*/
givenName?: string

/**
* User specified unique constraint name.
*/
givenName?: string

// ---------------------------------------------------------------------
// Constructor
// ---------------------------------------------------------------------
Expand Down

0 comments on commit 487ceb4

Please sign in to comment.