-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Issue with a ordering by @VirtualColumn #10135
Comments
Same bug on postgres |
any solution? |
I also have an error when I try to sort by virtual column:
All works fine until I want to sort by virtual column via |
I have the same problem, it's working perfectly when you filter (using |
I believe the issue lies in not having a double quote around the alias(virtual column name) in the generated query while using order by. |
Has anyone found a solution yet? Today I spent a whole afternoon searching and it seems that the development team has not provided any solution to this problem. Using limit() instead of take() will allow you to use orderBy(), but the returned data will be missing if the query entity uses JOIN :( |
same issue |
same |
Issue description
There is a issue in applying order by per a VirtualColumn
Expected Behavior
I'm expecting to have availability to order by a virtual column in the same way as the normal column.
Actual Behavior
In case I have a queryBuilder and I have a situation like this:
const queryBuilder = this.someRepository.createQueryBuilder('s');
queryBuilder.innerJoinAndSelect('s.relation', 'r');
queryBuilder.take(take);
queryBuilder.skip(skip);
queryBuilder.orderBy(
**s.virtualColumn**
, 'desc');I cannot process sorting by s.virtualColumn because the SQL query uses an alias named
SELECT (query of my virtual column) as s_virtualColumn
Error that I'm getting:
Unknown column 's.virtualColumn' in 'order clause'
There also no way to process ordering by queryBuilder.orderBy(
**s_virtualColumn**
, 'desc');Because typeORM wraps everything to a DISTINCT (something like this #4998)
Expression #1 of ORDER BY clause is not in SELECT list, references column 'distinctAlias.s_virtualColumn'
As I researched there is no that kind of problem when I'm not using take/skip but I need that because of joins and pagination.
It would be fine to treat a virtual column as a normal column so we can easily order by that since that is part of the object.
Steps to reproduce
Already described in the Actual Behaviour section.
My virtual column calculates some average values that I need to use for sorting.
I'm unable to order by a virtual column since the query is generated in this way:
queryBuilder.orderBy(
s.virtualColumn
, 'DESC');'SELECT
s
.id
ASs_id
,s
.column
ASs_column
, (query of my virtual column) as s_virtualColumn FROM .... ORDER BYs
.virtualColumn
DESCMy entity has a virtual column:
@VirtualColumn({
query: (alias) =>
some query where s.id = ${alias}.id
})
virtualColumn: number;
at the end of the query builder I'm expecting results by calling
await queryBuilder.getManyAndCount();
It's maybe also related to the #4742
@pleerock Any idea?
My Environment
Additional Context
No response
Relevant Database Driver(s)
Are you willing to resolve this issue by submitting a Pull Request?
No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
The text was updated successfully, but these errors were encountered: