mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fix: preserve useIndex when cloning a QueryExpressionMap (or a QueryBuilder) (#10679)
* fix: preserve useIndex when cloning a QueryExpressionMap Closes #10678 * test: add test related to issue #10678
This commit is contained in:
parent
1ea3a5eb06
commit
66ee307784
@ -518,6 +518,7 @@ export class QueryExpressionMap {
|
||||
map.offset = this.offset
|
||||
map.skip = this.skip
|
||||
map.take = this.take
|
||||
map.useIndex = this.useIndex
|
||||
map.lockMode = this.lockMode
|
||||
map.onLocked = this.onLocked
|
||||
map.lockVersion = this.lockVersion
|
||||
|
||||
13
test/github-issues/10678/entity/user.ts
Normal file
13
test/github-issues/10678/entity/user.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { Column, Entity, Index, PrimaryGeneratedColumn } from "../../../../src"
|
||||
|
||||
@Entity({
|
||||
name: "user",
|
||||
})
|
||||
export class User {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Index("IDX_name")
|
||||
@Column({ nullable: true })
|
||||
name: string
|
||||
}
|
||||
38
test/github-issues/10678/issue-10678.ts
Normal file
38
test/github-issues/10678/issue-10678.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import "reflect-metadata"
|
||||
import {
|
||||
createTestingConnections,
|
||||
closeTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
} from "../../utils/test-utils"
|
||||
import { DataSource } from "../../../src/data-source/DataSource"
|
||||
import { expect } from "chai"
|
||||
import { User } from "./entity/user"
|
||||
|
||||
describe("github issues > #10678 useIndex is not preserved when cloning a QueryExpressionMap (or a QueryBuilder) instance", () => {
|
||||
let dataSources: DataSource[]
|
||||
before(
|
||||
async () =>
|
||||
(dataSources = await createTestingConnections({
|
||||
entities: [__dirname + "/entity/*{.js,.ts}"],
|
||||
schemaCreate: true,
|
||||
dropSchema: true,
|
||||
enabledDrivers: ["aurora-mysql", "mysql", "mariadb"],
|
||||
})),
|
||||
)
|
||||
beforeEach(() => reloadTestingDatabases(dataSources))
|
||||
after(() => closeTestingConnections(dataSources))
|
||||
|
||||
it("should preserve the useIndex property when a QueryBuilder instance is cloned", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
const useIndex = "IDX_name"
|
||||
const qb = dataSource
|
||||
.getRepository(User)
|
||||
.createQueryBuilder("u")
|
||||
.useIndex(useIndex)
|
||||
|
||||
expect(qb.expressionMap.useIndex).to.equal(useIndex)
|
||||
expect(qb.clone().expressionMap.useIndex).to.equal(useIndex)
|
||||
}),
|
||||
))
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user