diff --git a/src/query-builder/SelectQueryBuilder.ts b/src/query-builder/SelectQueryBuilder.ts index bf3ebe7194..7eabeca0e3 100644 --- a/src/query-builder/SelectQueryBuilder.ts +++ b/src/query-builder/SelectQueryBuilder.ts @@ -3582,7 +3582,7 @@ export class SelectQueryBuilder embedPrefix?: string, ) { for (let key in select) { - if (select[key] === undefined) continue + if (select[key] === undefined || select[key] === false) continue const propertyPath = embedPrefix ? embedPrefix + "." + key : key const column = diff --git a/test/github-issues/8796/entity/User.ts b/test/github-issues/8796/entity/User.ts new file mode 100644 index 0000000000..d19bc746c8 --- /dev/null +++ b/test/github-issues/8796/entity/User.ts @@ -0,0 +1,16 @@ +import { Column, Entity, PrimaryColumn } from "../../../../src" + +@Entity() +export class User { + @PrimaryColumn({ type: "int", nullable: false }) + id: number + + @Column() + firstName: string + + @Column() + lastName: string + + @Column() + github: string +} diff --git a/test/github-issues/8796/issue-8796.ts b/test/github-issues/8796/issue-8796.ts new file mode 100644 index 0000000000..32cd0f2f88 --- /dev/null +++ b/test/github-issues/8796/issue-8796.ts @@ -0,0 +1,57 @@ +import "reflect-metadata" +import { + createTestingConnections, + closeTestingConnections, + reloadTestingDatabases, +} from "../../utils/test-utils" +import { Connection } from "../../../src/connection/Connection" +import { expect } from "chai" +import { User } from "../8796/entity/User" + +describe("github issues > #8796 New find select object api should support false values as expected", () => { + let connections: Connection[] + + const user: User = { + id: 1, + firstName: "Christian", + lastName: "Fleury", + github: "chfleury", + } + + const expectedUser: Partial = { + id: 1, + firstName: "Christian", + } + + before( + async () => + (connections = await createTestingConnections({ + entities: [__dirname + "/entity/*{.js,.ts}"], + schemaCreate: true, + dropSchema: true, + })), + ) + beforeEach(() => reloadTestingDatabases(connections)) + after(() => closeTestingConnections(connections)) + + it("should suport false value when selecting fields", () => + Promise.all( + connections.map(async (connection) => { + const userRepository = connection.getRepository(User) + + await userRepository.save(user) + + const foundUser = await userRepository.find({ + where: { id: 1 }, + select: { + id: true, + firstName: true, + lastName: undefined, + github: false, + }, + }) + + expect(foundUser[0]).to.deep.equal(expectedUser) + }), + )) +})