Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: discard duplicated columns on update (#8724)
Closes: #8723
- Loading branch information
1 parent
f3cfdd2
commit 0fc093d
Showing
4 changed files
with
65 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,21 @@ | ||
import { | ||
Column, | ||
Entity, | ||
OneToOne, | ||
JoinColumn, | ||
PrimaryColumn, | ||
} from "../../../../src"; | ||
import { User } from "./User"; | ||
|
||
@Entity() | ||
export class Photo { | ||
@PrimaryColumn({ type: "int", nullable: false }) | ||
id: number; | ||
|
||
@OneToOne(() => User, { nullable: true }) | ||
@JoinColumn({ name: "user_id" }) | ||
public user?: User; | ||
|
||
@Column({ name: "user_id", nullable: true }) | ||
public userId?: 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,14 @@ | ||
import { | ||
Column, | ||
Entity, | ||
PrimaryColumn, | ||
} from "../../../../src"; | ||
|
||
@Entity() | ||
export class User { | ||
@PrimaryColumn({ type: "int", nullable: false }) | ||
id: number; | ||
|
||
@Column() | ||
name: 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,28 @@ | ||
import "reflect-metadata"; | ||
import { createTestingConnections, closeTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { Connection } from "../../../src/connection/Connection"; | ||
import { User } from "./entity/User"; | ||
import { Photo } from "./entity/Photo"; | ||
|
||
describe("github issues > #8723 Fail on Update when reference exists together with FK: multiple assignments to same column ", () => { | ||
|
||
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 able to update when both reference and the id exist in the update object", () => Promise.all(connections.map(async connection => { | ||
const photoRepository = connection.getRepository(Photo); | ||
const userRepository = connection.getRepository(User); | ||
|
||
const user = await userRepository.save({ id: 1, name: "Test" }); | ||
const photo = await photoRepository.save({ id: 1 }); | ||
|
||
await photoRepository.update({ id: photo.id }, { user, userId: user.id }); | ||
}))); | ||
|
||
}); |