Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #8796 #8807

Merged
merged 4 commits into from
Mar 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/query-builder/SelectQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3582,7 +3582,7 @@ export class SelectQueryBuilder<Entity>
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 =
Expand Down
16 changes: 16 additions & 0 deletions test/github-issues/8796/entity/User.ts
Original file line number Diff line number Diff line change
@@ -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
}
57 changes: 57 additions & 0 deletions test/github-issues/8796/issue-8796.ts
Original file line number Diff line number Diff line change
@@ -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<User> = {
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)
}),
))
})