typeorm
typeorm copied to clipboard
Bug with @VirtualColumn not being returned correctly
Issue description
@VirtualColumn not being returned correctly
Expected Behavior
@Entity({ name: 'integrations' })
export class IntegrationEntity {
@Exclude()
@PrimaryGeneratedColumn('uuid')
id: string;
@ApiProperty()
@PrimaryColumn({ name: 'client_id', type: 'uuid' })
client_id: string;
@ApiProperty()
@VirtualColumn({ query: (alias) => `select "DMS" from config_client where "client_id"=${alias}.client_id` })
dms: string;
}
It was expected that @VirtualColumn would return the correct values according to the logic defined in the decorator.
{
"client_id": "1b97a2d2-91b8-4dab-9593-906da6d95d36",
"dms": "NBS"
}
Actual Behavior
@Entity({ name: 'integrations' })
export class IntegrationEntity {
@Exclude()
@PrimaryGeneratedColumn('uuid')
id: string;
@ApiProperty()
@PrimaryColumn({ name: 'client_id', type: 'uuid' })
client_id: string;
@ApiProperty()
@VirtualColumn({ query: (alias) => `select "DMS" from config_client where "client_id"=${alias}.client_id` })
dms: string;
}
DNS column is not being returned
{
"client_id": "1b97a2d2-91b8-4dab-9593-906da6d95d36"
}
Steps to reproduce
- Add the @VirtualColumn decorator to an entity or class.
- Define the expected logic for the virtual value.
- Observe the obtained result.
My Environment
Dependency | Version |
---|---|
Operating System | windows 10 |
Node.js version | 18.18.0 |
Typescript version | 5.3.3 |
TypeORM version | 0.3.19 |
Additional Context
No response
Relevant Database Driver(s)
- [ ] aurora-mysql
- [ ] aurora-postgres
- [ ] better-sqlite3
- [ ] cockroachdb
- [ ] cordova
- [ ] expo
- [ ] mongodb
- [ ] mysql
- [ ] nativescript
- [ ] oracle
- [X] postgres
- [ ] react-native
- [ ] sap
- [ ] spanner
- [ ] sqlite
- [ ] sqlite-abstract
- [ ] sqljs
- [ ] sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, and I know how to start.
Same here, with latest 0.3.19. Locking the version to 0.3.17 fixed it. Not sure if breaking changes introduced in 0.3.18 or 0.3.19.
https://github.com/typeorm/typeorm/pull/10432/files
How do you select the virtual column, can you give an example of the implementation?
As an example, usage of the repository findOne
or findOneOrFail
functions, without the select
option, will return virtual columns by default in version 0.3.17. Version 0.3.19 omits virtual columns with the same usage pattern.
Yeah, we are experiencing the same issue, virtual column stopped working. this is urgent‼️
Can you create a PR to fix the issue introduced in #10432 but also keep #10431 fixed? If not, I think we should create a PR reverting the changes from #10432
@jorenvandeweyer I think we should create a PR reverting the changes from #10432, because analyzing the code from PR #10432 it just made all virtual columns return null, in his case I think he should use a transformation to convert empty to null
Same here ->
Upgraded from 0.3.17 to 0.3.19 (latest) and everything related to VirtualColumn breaks.
Same here ->
the @VirtualColumn
decorator does not work on 0.3.19
version
I have the Same issue.
Upgraded from 0.3.17 to 0.3.19 and everything related to VirtualColumn breaks.
not working with us too after update from 0.3.17
still broken in 0.3.20
Any news on open MR ?
@gwen1230 I think they are not going to fix this because not much people are using virtual column, so for stability either downgrade or switch to Prisma instead.
I've seen this too after upgrading. A possible workaround is to pass a select which includes the virtual column, but this isn't great as you then have to pass all the fields that you want to be returned.
I've seen this too after upgrading. A possible workaround is to pass a select which includes the virtual column, but this isn't great as you then have to pass all the fields that you want to be returned.
Tried this but didn't seem to work, TypeORM is trying to load the column from the actual table. Did you have any success with it?
If the general direction is to manually select virtualcolumns that would also be fine (there should probably be an eager option on the decorator in that case). The previous virtualcolumn functionality was ideal imo. Curious why these breaking changes were implemented from a benefit stand-point.
Will try and compare prev and curr implementation for possible ideas
Any updates? I would appreciate some fix here it will be really helpful 🙏🏼
any updates on this?
A fix for this would be helpful, we were just affected by this in production and are going to have to downgrade or patch it internally until it is fixed!
hopefully either https://github.com/typeorm/typeorm/pull/10777 or https://github.com/typeorm/typeorm/pull/10698 can be reviewed soon!
Any news on this, please?
Many production environments are affected by this, please.
@fatlirmorina The solution is to install 0.3.17
Any news on this
Any news on this
Any news on this
Any news on this
Unfortunately not, still awaiting PR approval.
Have you got any update on this yet?
Have you got any update on this yet?
Unfortunately still no response. I'm already thinking about creating a fork of the project.
+1
I'd also like to offer my own fork as a solution. I took e7649d2746f907ff36b1efb600402dedd5f5a499 and applied the fix of #10698, and it is published as @helveg/typeorm
. I won't maintain the fork any further, but people looking for typeorm 0.3.20
with working VirtualColumns can install it with the following npm-alias:
npm install typeorm@npm:@helveg/[email protected]
which will fix this issue.
+1