-
-
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: save does not return id, save does not return generated (#7336)
* fix save does not return id * allow subject.generatedMap to be null/undefined * stop using coalescing operator * actually allow generated map to bu undefined * add test * use doublequotes * remove singlequotes * fix formatting
- Loading branch information
Showing
4 changed files
with
77 additions
and
4 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,9 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from "../../../../src"; | ||
|
||
@Entity() | ||
export class TestChild { | ||
@Column() | ||
public value: string; | ||
@PrimaryGeneratedColumn("uuid") | ||
public uuid: 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,15 @@ | ||
import { Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from "../../../../src"; | ||
import { TestChild } from "./TestChild"; | ||
|
||
@Entity() | ||
export class TestParent { | ||
@OneToOne("TestChild", { | ||
nullable: true, | ||
eager: true, | ||
cascade: true, | ||
}) | ||
@JoinColumn() | ||
public child: TestChild; | ||
@PrimaryGeneratedColumn("uuid") | ||
public uuid: 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,45 @@ | ||
import "reflect-metadata"; | ||
|
||
import { assert } from "chai"; | ||
|
||
import { Connection } from "../../../src"; | ||
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { TestChild } from "./entity/TestChild"; | ||
import { TestParent } from "./entity/TestParent"; | ||
|
||
describe("github issues > #5520 save does not return generated id if object to save contains a many to one relationship with an undefined id", () => { | ||
let connections: Connection[]; | ||
before( | ||
async () => | ||
(connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
})) | ||
); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should generate parents and childs uuid and return them", () => | ||
Promise.all( | ||
connections.map(async (connection) => { | ||
let entity = new TestParent(); | ||
let entityChild = new TestChild(); | ||
entityChild.value = "test"; | ||
entity.child = entityChild; | ||
|
||
let response = await connection | ||
.getRepository(TestParent) | ||
.save(entity); | ||
|
||
assert( | ||
response.uuid, | ||
"parent uuid should be generated and set" | ||
); | ||
assert( | ||
response.child.uuid, | ||
"child uuid should be generated and set" | ||
); | ||
}) | ||
)); | ||
}); |