-
-
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: incorrect sorting of entities with multi-inheritances (#9406)
* Fixed sorting of entities with multi-inheritances * prettier * added test case --------- Co-authored-by: Alex Messer <dmzt08@gmail.com>
- Loading branch information
1 parent
adce698
commit 54ca9dd
Showing
6 changed files
with
95 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,29 @@ | ||
import { | ||
Column, | ||
Entity, | ||
ManyToOne, | ||
PrimaryGeneratedColumn, | ||
} from "../../../../src/index.js" | ||
import { ChangeLog } from "./ChangeLog.js" | ||
|
||
@Entity() | ||
export class Change<T> { | ||
@PrimaryGeneratedColumn("increment") | ||
id: number | ||
|
||
@Column("varchar", { nullable: false, length: 255 }) | ||
propertyName: string | ||
|
||
@Column("json", { nullable: true }) | ||
oldValue?: any | ||
|
||
@Column("json", { nullable: true }) | ||
newValue?: any | ||
|
||
@ManyToOne(() => ChangeLog, { | ||
cascade: false, | ||
nullable: false, | ||
onDelete: "CASCADE", | ||
}) | ||
public log: ChangeLog<T> | ||
} |
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 { OneToMany, ChildEntity } from "../../../../src/index.js" | ||
import { Change } from "./Change.js" | ||
import { Log } from "./Log.js" | ||
|
||
@ChildEntity() | ||
export abstract class ChangeLog<T> extends Log { | ||
@OneToMany(() => Change, (change) => change.log, { cascade: true }) | ||
changes: Change<T>[] | ||
} |
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,7 @@ | ||
import { ChildEntity } from "../../../../src/index.js" | ||
import { ChangeLog } from "./ChangeLog.js" | ||
|
||
export class Email {} | ||
|
||
@ChildEntity() | ||
export class EmailChanged extends ChangeLog<Email> {} |
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 { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
TableInheritance, | ||
} from "../../../../src/index.js" | ||
|
||
@Entity() | ||
@TableInheritance({ column: { type: "varchar", name: "type" } }) | ||
export abstract class Log { | ||
@PrimaryGeneratedColumn("increment") | ||
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,35 @@ | ||
import "reflect-metadata" | ||
import { | ||
closeTestingConnections, | ||
createTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils" | ||
import { DataSource } from "../../../src/index.js" | ||
import { Email, EmailChanged } from "./entity/EmailChanged.js" | ||
import { Change } from "./entity/Change.js" | ||
import { Log } from "./entity/Log.js" | ||
|
||
describe("github issues > #9405 Incorrect subject sorting with multi-inheritance entities", () => { | ||
let dataSources: DataSource[] | ||
before( | ||
async () => | ||
(dataSources = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["postgres"], | ||
})), | ||
) | ||
beforeEach(() => reloadTestingDatabases(dataSources)) | ||
after(() => closeTestingConnections(dataSources)) | ||
|
||
it("should correctly sort entities with multi-inheritances", () => | ||
Promise.all( | ||
dataSources.map(async (dataSource) => { | ||
const emailChanged = new EmailChanged() | ||
const change = new Change<Email>() | ||
change.propertyName = "Example" | ||
emailChanged.changes = [change] | ||
|
||
await dataSource.getRepository(Log).save(emailChanged) | ||
}), | ||
)) | ||
}) |