-
-
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: correctly get referenceColumn value in
getEntityValueMap
(#7005)
* test: add test case (#7002) * fix: correctly get referenceColumn value in `getEntityValueMap`
- Loading branch information
Showing
4 changed files
with
86 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,19 @@ | ||
import { | ||
Column, | ||
Entity, | ||
OneToOne, | ||
PrimaryGeneratedColumn, | ||
} from "../../../../src"; | ||
import { Foo } from "./Foo"; | ||
|
||
@Entity() | ||
export class Bar { | ||
@PrimaryGeneratedColumn("increment") | ||
id: number; | ||
|
||
@Column() | ||
title: string; | ||
|
||
@OneToOne(() => Foo, foo => foo.bar, { cascade: true, eager: true }) | ||
foo: Foo; | ||
} |
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, | ||
CreateDateColumn, | ||
Entity, | ||
JoinColumn, | ||
OneToOne, | ||
PrimaryColumn, | ||
} from "../../../../src"; | ||
import { Bar } from "./Bar"; | ||
|
||
@Entity() | ||
export class Foo { | ||
@PrimaryColumn() | ||
id: number; | ||
|
||
@Column() | ||
text: string; | ||
|
||
@OneToOne(() => Bar, b => b.foo, { primary: true }) | ||
@JoinColumn({ name: "id", referencedColumnName: "id" }) | ||
bar: Bar; | ||
|
||
@CreateDateColumn() | ||
d: Date; | ||
} |
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,40 @@ | ||
import "reflect-metadata"; | ||
|
||
import { Connection } from "../../../src/connection/Connection"; | ||
import { | ||
closeTestingConnections, | ||
createTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils"; | ||
import { Bar } from "./entity/Bar"; | ||
import { Foo } from "./entity/Foo"; | ||
|
||
describe("github issues > #7002 cascade save fails if the child entity has CreateDateColumn and PK as JoinColumn", () => { | ||
let connections: Connection[]; | ||
before( | ||
async () => | ||
(connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
enabledDrivers: ["mysql", "postgres"], | ||
})) | ||
); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("save an entity having a child entity with shared PK and CreatedDateColumn by cascade", () => | ||
Promise.all( | ||
connections.map(async (connection) => { | ||
const foo = new Foo(); | ||
foo.text = "This is a feature post"; | ||
|
||
await connection.manager.save( | ||
connection.getRepository(Bar).create({ | ||
title: "Feature Post", | ||
foo, | ||
}) | ||
); | ||
}) | ||
)); | ||
}); |