Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: option to disable foreign keys creation (#7277)
* Add relation option "createForeignKeyConstraints" * feat: add createForeignKeyConstraints relation option This new option allows to create relation without using foreign keys Closes: #3120 * test: add cases for createForeignKeyConstraints relation option * docs: createForeignKeyConstraints relation option * test: remove .only * chore: remove unused test files * test: add case checking if relation without foreign key works as expected * fix: register join columns for relation without foreign key Closes: #3120 Co-authored-by: Alexander Bolshakov <alexanderb@cubedmobile.com>
- Loading branch information
Showing
15 changed files
with
339 additions
and
15 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
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
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
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
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,14 @@ | ||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
import {Column} from "../../../../src/decorator/columns/Column"; | ||
|
||
@Entity() | ||
export class ActionDetails { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
description: 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,42 @@ | ||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
import {Column} from "../../../../src/decorator/columns/Column"; | ||
import {JoinColumn} from "../../../../src/decorator/relations/JoinColumn"; | ||
import {JoinTable} from "../../../../src/decorator/relations/JoinTable"; | ||
import {ManyToOne} from "../../../../src/decorator/relations/ManyToOne"; | ||
import {ManyToMany} from "../../../../src/decorator/relations/ManyToMany"; | ||
import {OneToOne} from "../../../../src/decorator/relations/OneToOne"; | ||
import {ActionDetails} from "./ActionDetails"; | ||
import {Address} from "./Address"; | ||
import {Person} from "./Person"; | ||
|
||
@Entity() | ||
export class ActionLog { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
date: Date; | ||
|
||
@Column() | ||
action: string; | ||
|
||
@ManyToOne(type => Person, { | ||
createForeignKeyConstraints: false | ||
}) | ||
person: Person; | ||
|
||
@ManyToMany(type => Address, { | ||
createForeignKeyConstraints: false | ||
}) | ||
@JoinTable() | ||
addresses: Address[]; | ||
|
||
@OneToOne(type => ActionDetails, { | ||
createForeignKeyConstraints: false | ||
}) | ||
@JoinColumn() | ||
actionDetails: ActionDetails; | ||
|
||
} |
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,24 @@ | ||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
import {Column} from "../../../../src/decorator/columns/Column"; | ||
import {ManyToMany} from "../../../../src/decorator/relations/ManyToMany"; | ||
import {Person} from "./Person"; | ||
|
||
@Entity() | ||
export class Address { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
country: string; | ||
|
||
@Column() | ||
city: string; | ||
|
||
@Column() | ||
street: string; | ||
|
||
@ManyToMany(type => Person, person => person.addresses) | ||
people: Person[]; | ||
} |
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,14 @@ | ||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
import {Column} from "../../../../src/decorator/columns/Column"; | ||
|
||
@Entity() | ||
export class Company { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
name: 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,18 @@ | ||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
import {Column} from "../../../../src/decorator/columns/Column"; | ||
import {OneToOne} from "../../../../src/decorator/relations/OneToOne"; | ||
import {Person} from "./Person"; | ||
|
||
@Entity() | ||
export class Passport { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
passportNumber: string; | ||
|
||
@OneToOne(type => Person, person => person.passport) | ||
owner: Person; | ||
} |
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,33 @@ | ||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
import {Column} from "../../../../src/decorator/columns/Column"; | ||
import {JoinColumn} from "../../../../src/decorator/relations/JoinColumn"; | ||
import {JoinTable} from "../../../../src/decorator/relations/JoinTable"; | ||
import {ManyToOne} from "../../../../src/decorator/relations/ManyToOne"; | ||
import {ManyToMany} from "../../../../src/decorator/relations/ManyToMany"; | ||
import {OneToOne} from "../../../../src/decorator/relations/OneToOne"; | ||
import {Address} from "./Address"; | ||
import {Company} from "./Company"; | ||
import {Passport} from "./Passport"; | ||
|
||
@Entity() | ||
export class Person { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
name: string; | ||
|
||
@ManyToOne(type => Company) | ||
company: Company; | ||
|
||
@ManyToMany(type => Address, address => address.people) | ||
@JoinTable() | ||
addresses: Address[]; | ||
|
||
@OneToOne(type => Passport, passport => passport.owner) | ||
@JoinColumn() | ||
passport: Passport; | ||
|
||
} |
Oops, something went wrong.