Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: entity value for date columns that are related (#8027)
- Loading branch information
1 parent
ba366f2
commit 5a3767f
Showing
4 changed files
with
73 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,14 @@ | ||
import { BaseEntity, Entity, JoinColumn, OneToMany, PrimaryColumn } from "../../../../src"; | ||
import { ScheduledSailing } from "./ScheduledSailing"; | ||
|
||
@Entity() | ||
export class Sailing extends BaseEntity { | ||
@PrimaryColumn() | ||
scheduled_departure_time: Date; | ||
|
||
@OneToMany(() => ScheduledSailing, (scheduledSailing) => scheduledSailing.sailing) | ||
@JoinColumn([ | ||
{ referencedColumnName: "scheduled_departure_time", name: "scheduled_departure_time" } | ||
]) | ||
scheduled_sailings: ScheduledSailing[]; | ||
} |
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,17 @@ | ||
import { BaseEntity, Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "../../../../src"; | ||
import { Sailing } from "./Sailing"; | ||
|
||
@Entity() | ||
export class ScheduledSailing extends BaseEntity { | ||
@PrimaryColumn() | ||
scheduled_departure_time: Date; | ||
|
||
@Column() | ||
scheduled_arrival_time: Date; | ||
|
||
@ManyToOne(() => Sailing, (sailing) => sailing.scheduled_sailings) | ||
@JoinColumn([ | ||
{ referencedColumnName: "scheduled_departure_time", name: "scheduled_departure_time" } | ||
]) | ||
sailing: Sailing; | ||
} |
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 { expect } from "chai"; | ||
import "reflect-metadata"; | ||
import { Connection } from "../../../src"; | ||
import { closeTestingConnections, createTestingConnections } from "../../utils/test-utils"; | ||
import { Sailing } from "./entity/Sailing"; | ||
import { ScheduledSailing } from "./entity/ScheduledSailing"; | ||
|
||
describe("github issues > #8026 Inserting a value for a column that has a relation, and is also a date, results in the value being inserted as DEFAULT", () => { | ||
|
||
let connections: Connection[]; | ||
|
||
before(async () => connections = await createTestingConnections({ | ||
entities: [Sailing, ScheduledSailing], | ||
schemaCreate: true, | ||
dropSchema: true | ||
})); | ||
|
||
after(() => closeTestingConnections(connections)); | ||
|
||
it("it should include a related date column in the constructed query", async () => await Promise.all(connections.map(async connection => { | ||
|
||
let queryBuilder = await connection.createQueryBuilder(); | ||
|
||
const insertValue = { | ||
scheduled_departure_time: new Date(), | ||
scheduled_arrival_time: new Date(), | ||
} | ||
|
||
const [query, params] = await queryBuilder | ||
.insert() | ||
.into(ScheduledSailing) | ||
.values([insertValue]) | ||
.getQueryAndParameters() | ||
|
||
expect(query.includes("DEFAULT")).to.be.false; | ||
expect(params).length(2); | ||
|
||
}))); | ||
|
||
}); |