We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
As per https://typeorm.io/#/find-options/basic-options, typeorm now supports syntax like:
typeorm
userRepository.find({ select: { firstName: true, lastName: true, }, })
However, if you change one of the values to false, like:
false
userRepository.find({ select: { firstName: true, lastName: false, // note false }, })
Then it makes no difference. lastName is still selected which does not seem intuitive.
lastName
However, if the value is specified as undefined then the field will not be selected:
undefined
userRepository.find({ select: { firstName: true, lastName: undefined, // note undefined }, })
It would be great if false was handled intuitively so that simple boolean conditions can be specified for conditional selection.
Note that the relations option has a similar interface and it does handle false values as expected.
relations
Could be simple as changing the following line:
typeorm/src/query-builder/SelectQueryBuilder.ts
Line 3586 in 68a5c23
to:
if (!select[key]) continue;
???
undefined can be specified instead of false but this complicates code for conditional selects.
The select implementation is also inconsistent with the relations implementation which does handle false values as expected.
select
The new select and relations API was recently released in https://github.com/typeorm/typeorm/releases/tag/0.3.0.
n/a
The text was updated successfully, but these errors were encountered:
I suggest to simply do it as:
if (select[key] === undefined || select[key] === false) continue
and add test for this change. Simply to contribute.
Sorry, something went wrong.
fix: find select object api should support false values #8796 (#8807)
9ac8e9e
* fix: select supports false value instead of only undefined * test: issue-8796 * refactor: add test description * refactor: format code
fix: find select object api should support false values typeorm#8796 (t…
dacac45
…ypeorm#8807) * fix: select supports false value instead of only undefined * test: issue-8796 * refactor: add test description * refactor: format code
Successfully merging a pull request may close this issue.
Feature Description
The Problem
As per https://typeorm.io/#/find-options/basic-options,
typeorm
now supports syntax like:However, if you change one of the values to
false
, like:Then it makes no difference.
lastName
is still selected which does not seem intuitive.However, if the value is specified as
undefined
then the field will not be selected:It would be great if
false
was handled intuitively so that simple boolean conditions can be specified for conditional selection.Note that the
relations
option has a similar interface and it does handlefalse
values as expected.The Solution
Could be simple as changing the following line:
typeorm/src/query-builder/SelectQueryBuilder.ts
Line 3586 in 68a5c23
to:
???
Considered Alternatives
undefined
can be specified instead offalse
but this complicates code for conditional selects.The
select
implementation is also inconsistent with therelations
implementation which does handlefalse
values as expected.Additional Context
The new
select
andrelations
API was recently released in https://github.com/typeorm/typeorm/releases/tag/0.3.0.Relevant Database Driver(s)
n/a
Are you willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: