Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: create correct children during cascade saving entities with STI (#…
…9034) * test: test saving disciminators STI, cascading This commit adds an test for checking whether discriminators are saved correctly when saving a field with cascade that uses Single-Table-Inheritance. Related to: #7758 * fix: Create correct children with STI This commit fixes the `create` function for EntityManager and Repository to create entities of correct type when using Single Table Inheritance. Refactors the otherwise repeated code into a new function on EntityMetadata. Related to: #7758 * test: check STI type setting discriminator manually Related to: #9033 * feature: allow setting discriminator value manually This commit allows using an instance of a base class in a Single Table Inheritance scenario and setting the discriminator value manually. Related to: #9033 * test: test saving disciminators with trees in STI This commit adds an test for checking whether discriminators are saved correctly when saving a tree that also uses Single-Table-Inheritance. Related to: #7758 * fix: Create correct children with STI and trees This commit fixes the `create` function for EntityManager and TreeRepository to create entities of correct type when using Single Table Inheritance and complex inheritance with Trees. Related to: #7758
- Loading branch information
1 parent
96b7ee4
commit 06c1e98
Showing
18 changed files
with
507 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
Column, | ||
Entity, | ||
ManyToOne, | ||
PrimaryGeneratedColumn, | ||
TableInheritance, | ||
} from "../../../../src" | ||
|
||
import { PersonEntity } from "./Person" | ||
|
||
@Entity("animal") | ||
@TableInheritance({ column: { type: "varchar", name: "type" } }) | ||
export class AnimalEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Column({ type: "varchar" }) | ||
name: string | ||
|
||
@ManyToOne(() => PersonEntity, ({ pets }) => pets, { | ||
onDelete: "CASCADE", | ||
onUpdate: "CASCADE", | ||
}) | ||
person: PersonEntity | ||
} |
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 { AnimalEntity } from "./Animal" | ||
|
||
@ChildEntity("cat") | ||
export class CatEntity extends AnimalEntity { | ||
// Cat stuff | ||
@Column() | ||
livesLeft: 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,16 @@ | ||
import { | ||
Column, | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
TableInheritance, | ||
} from "../../../../src" | ||
|
||
@Entity("content") | ||
@TableInheritance({ column: { type: "varchar", name: "type" } }) | ||
export class Content { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Column() | ||
title: 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 { ChildEntity, Column } from "../../../../src" | ||
|
||
import { AnimalEntity } from "./Animal" | ||
|
||
@ChildEntity("dog") | ||
export class DogEntity extends AnimalEntity { | ||
// Dog stuff | ||
@Column() | ||
steaksEaten: 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,12 @@ | ||
import { ChildEntity, Column, TreeChildren } from "../../../../src" | ||
|
||
import { OperatorTreeEntry } from "./OperatorTreeEntry" | ||
|
||
@ChildEntity("nnary") | ||
export class NnaryOperator extends OperatorTreeEntry { | ||
@TreeChildren({ cascade: true }) | ||
children: OperatorTreeEntry[] | ||
|
||
@Column() | ||
operator: 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,11 @@ | ||
import { ChildEntity, Column } from "../../../../src" | ||
|
||
import { OperatorTreeEntry } from "./OperatorTreeEntry" | ||
|
||
@ChildEntity("number") | ||
export class NumberEntry extends OperatorTreeEntry { | ||
@Column({ | ||
type: "float", | ||
}) | ||
value: 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,19 @@ | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
TableInheritance, | ||
Tree, | ||
TreeParent, | ||
} from "../../../../src" | ||
import type { NnaryOperator } from "./NnaryOperator" | ||
|
||
@Entity() | ||
@TableInheritance({ pattern: "STI", column: { type: "varchar" } }) | ||
@Tree("closure-table") | ||
export class OperatorTreeEntry { | ||
@PrimaryGeneratedColumn("uuid") | ||
id: string | ||
|
||
@TreeParent() | ||
parent?: NnaryOperator | ||
} |
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,30 @@ | ||
import { | ||
Entity, | ||
JoinColumn, | ||
OneToMany, | ||
OneToOne, | ||
PrimaryGeneratedColumn, | ||
} from "../../../../src" | ||
|
||
import { AnimalEntity } from "./Animal" | ||
import { Content } from "./Content" | ||
|
||
@Entity({ name: "person" }) | ||
export class PersonEntity { | ||
@PrimaryGeneratedColumn() | ||
id!: number | ||
|
||
@OneToMany(() => AnimalEntity, ({ person }) => person, { | ||
cascade: true, | ||
eager: true, | ||
}) | ||
pets!: AnimalEntity[] | ||
|
||
@OneToOne(() => Content, { | ||
cascade: true, | ||
eager: true, | ||
nullable: true, | ||
}) | ||
@JoinColumn() | ||
content?: Content | ||
} |
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,8 @@ | ||
import { ChildEntity, Column } from "../../../../src" | ||
import { Content } from "./Content" | ||
|
||
@ChildEntity("photo") | ||
export class Photo extends Content { | ||
@Column() | ||
size: number | ||
} |
Oops, something went wrong.