-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: include asExpression columns in returning clause (#10632)
* fix: include asExpression columns in returning clause Closes: #8450 * test: add test for issue #8450
- Loading branch information
1 parent
8aa8690
commit f232ba7
Showing
4 changed files
with
61 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Entity } from "../../../../src/decorator/entity/Entity" | ||
import { PrimaryColumn } from "../../../../src/decorator/columns/PrimaryColumn" | ||
import { Column } from "../../../../src/decorator/columns/Column" | ||
|
||
@Entity("user") | ||
export class UserEntity { | ||
@PrimaryColumn("int") | ||
id: number | ||
|
||
@Column({ | ||
type: "int", | ||
generatedType: "STORED", | ||
asExpression: "id * 2", | ||
}) | ||
generated: 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,38 @@ | ||
import "reflect-metadata" | ||
import { | ||
closeTestingConnections, | ||
createTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils" | ||
import { UserEntity } from "./entity/UserEntity" | ||
import { expect } from "chai" | ||
import { DataSource } from "../../../src" | ||
|
||
describe("github issues > #8450 Generated column not in RETURNING clause on save", () => { | ||
let connections: DataSource[] | ||
|
||
before( | ||
async () => | ||
(connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["postgres", "mysql"], | ||
})), | ||
) | ||
beforeEach(() => reloadTestingDatabases(connections)) | ||
after(() => closeTestingConnections(connections)) | ||
|
||
it("should populate an object with generated column values after saving", () => | ||
Promise.all( | ||
connections.map(async (connection) => { | ||
const user = new UserEntity() | ||
user.id = 100 | ||
|
||
expect(user.generated).to.be.undefined | ||
|
||
await connection.manager.save(user) | ||
|
||
expect(user.generated).to.be.a("number") | ||
expect(user.generated).to.be.equal(user.id * 2) | ||
}), | ||
)) | ||
}) |