-
Notifications
You must be signed in to change notification settings - Fork 43
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
Support TypeORM VirtualColumn #67
Comments
Interesting, could it be because TypORM version is not the same? Do you use yarn by any change? If so could you try to add the following:
Then do This is actually a quite awesome feature! |
Agreed, it's an awesome feature and also, I appreciate you taking over as maintainer of this project. I use npm, but did something similar to pin the typeorm version
But no luck, still getting the same error on filter and sort. I edited the main post with this, just FYI:
So selecting the VirtualColumn field does return the appropriate calculated value, it just doesn't work on filter and sort. |
Okay thanks for the explanation, will try to check this out somewhere in the coming days. |
After some digging it's because the query services tries to filter / order on it as a normal database field, like We could make a simple fix by checking if the column we are filtering/ordering on has the property In the case of sorting it would look like: public applySorting<T extends Sortable<Entity>>(qb: T, sorts?: SortField<Entity>[], alias?: string): T {
if (!sorts) {
return qb
}
return sorts.reduce((prevQb, { field, direction, nulls }) => {
const columnMetadata = this.repo.metadata.columns.find((col) => col.propertyName === field)
let col = alias ? `${alias}.${field as string}` : `${field as string}`
// If the column is virtual we need to use the actual selected field as it does not exist in the database
if (columnMetadata?.isVirtualProperty) {
col = `"${alias ? `${alias}_${field as string}` : `${field as string}`}"`
}
return prevQb.addOrderBy(col, direction, nulls)
}, qb)
} |
Any update on this? Just bumped versions in Typeorm and would love to take advantage of nestjs-query functionality on the VirtualColumns. |
Just patched via |
@MrSquaare, would you be able to make a PR? |
@YeomansIII Unfortunately, after further testing, it doesn't seem to work with some databases (such as Postgres). |
Partly because what you are saying above, this solution is not correctly tested at all so can have unexpected behaviour with other drivers, also there was no response on the ticket for a while 😅 |
Any news about thaat issue ? Having the same issue when using where contidional, that code fix the sort. ERROR [ExceptionsHandler] Unknown column 'Quote.daysUntilDue' in 'where clause' |
Thanks @TriPSs ! |
Is your feature request related to a problem? Please describe.
A new @VirtualColumn decorator was recently added to TypeORM as a read-only virtual column that is generated with each
find
. It supports WHERE and ORDER BY filtering and sorting, however, nestjs-query does not seem to be generating the proper query code (straight SQL instead of TypeORM repository query)?I end up with the following GraphQL error:
I am able to successfully query the Field of the VirtualColumn, but as soon as I try to filter or sort, it says the column doesn't exist (it really doesn't, but the repository should handle that).
TypeORM PR for VirtualColumn feature:
typeorm/typeorm#9339
Have you read the Contributing Guidelines?
Yes
Describe the solution you'd like
Filtering and Sorting on a Virtual Column should work.
Describe alternatives you've considered
Getter/generated field, which does not allow filtering or sorting.
The text was updated successfully, but these errors were encountered: