forked from typeorm/typeorm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ignore changes for columns with
update: false
in persistence
Closes: typeorm#10249
- Loading branch information
Showing
3 changed files
with
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Column, Entity, PrimaryColumn } from "../../../../src"; | ||
|
||
@Entity() | ||
export class Example { | ||
@PrimaryColumn() | ||
id: string; | ||
|
||
@Column({ update: false }) | ||
notUpdatable: string; | ||
|
||
@Column() | ||
updatable: 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,51 @@ | ||
import "reflect-metadata"; | ||
import { createTestingConnections, closeTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { DataSource } from "../../../src/data-source/DataSource" | ||
import { expect } from "chai"; | ||
import { Example } from "./entity/example"; | ||
|
||
describe("github issues > #10249 Saving an entity is not possible if only columns with update: false are changed", () => { | ||
|
||
let dataSources: DataSource[]; | ||
before(async () => dataSources = await createTestingConnections({ | ||
entities: [Example], | ||
enabledDrivers: ["postgres"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
})); | ||
|
||
beforeEach(() => reloadTestingDatabases(dataSources)); | ||
after(() => closeTestingConnections(dataSources)); | ||
|
||
it("should ignore changes for columns with `update: false` on saving entity", () => Promise.all(dataSources.map(async dataSource => { | ||
await Promise.all( | ||
dataSources.map(async (dataSource) => { | ||
const manager = dataSource.manager; | ||
|
||
// create entity | ||
let exampleEntity = new Example(); | ||
exampleEntity.id = "1"; | ||
exampleEntity.notUpdatable = "value1"; | ||
exampleEntity.updatable = "value1"; | ||
await manager.save(exampleEntity); | ||
|
||
// updates only updatable value | ||
exampleEntity.notUpdatable = "value2"; | ||
exampleEntity.updatable = "value2"; | ||
await manager.save(exampleEntity); | ||
|
||
exampleEntity = (await manager.findOneBy(Example, { id: "1" }))!; | ||
expect(exampleEntity.notUpdatable).to.be.eql("value1"); | ||
expect(exampleEntity.updatable).to.be.eql("value2"); | ||
|
||
// if `update: false` column only specified, do nothing | ||
exampleEntity.notUpdatable = "value3"; | ||
await manager.save(exampleEntity); | ||
|
||
exampleEntity = (await manager.findOneBy(Example, { id: "1" }))!; | ||
expect(exampleEntity.notUpdatable).to.be.eql("value1"); | ||
expect(exampleEntity.updatable).to.be.eql("value2"); | ||
}) | ||
); | ||
}))); | ||
}); |