mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fix: sql expression when where parameter is empty array (#9691)
Closes: #9690 Co-authored-by: Dmitry Zotov <dmzt08@gmail.com>
This commit is contained in:
parent
7726f5ad1e
commit
7df2ccf69d
@ -4127,14 +4127,14 @@ export class SelectQueryBuilder<Entity extends ObjectLiteral>
|
||||
}
|
||||
|
||||
protected buildWhere(
|
||||
where: FindOptionsWhere<any>,
|
||||
where: FindOptionsWhere<any>[] | FindOptionsWhere<any>,
|
||||
metadata: EntityMetadata,
|
||||
alias: string,
|
||||
embedPrefix?: string,
|
||||
) {
|
||||
let condition: string = ""
|
||||
// let parameterIndex = Object.keys(this.expressionMap.nativeParameters).length;
|
||||
if (Array.isArray(where)) {
|
||||
if (Array.isArray(where) && where.length) {
|
||||
condition =
|
||||
"(" +
|
||||
where
|
||||
|
||||
7
test/github-issues/9690/entity/Foo.ts
Normal file
7
test/github-issues/9690/entity/Foo.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { Entity, PrimaryGeneratedColumn } from "../../../../src"
|
||||
|
||||
@Entity()
|
||||
export class Foo {
|
||||
@PrimaryGeneratedColumn({ name: "id" })
|
||||
id: number
|
||||
}
|
||||
30
test/github-issues/9690/issue-9690.ts
Normal file
30
test/github-issues/9690/issue-9690.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import "reflect-metadata"
|
||||
import { DataSource } from "../../../src"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
} from "../../utils/test-utils"
|
||||
import { Foo } from "./entity/Foo"
|
||||
|
||||
describe("github issues > #9690 Incorrect SQL expression if `where` parameter is empty array", () => {
|
||||
let dataSources: DataSource[]
|
||||
before(async () => {
|
||||
dataSources = await createTestingConnections({
|
||||
enabledDrivers: ["postgres"],
|
||||
entities: [Foo],
|
||||
schemaCreate: true,
|
||||
dropSchema: true,
|
||||
})
|
||||
})
|
||||
after(() => closeTestingConnections(dataSources))
|
||||
|
||||
it("should run without throw error", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
const repository = dataSource.getRepository(Foo)
|
||||
await repository.find({
|
||||
where: [],
|
||||
})
|
||||
}),
|
||||
))
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user