Error on aggregation column sorting
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[x] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
Hi there! I’ve faced a problem while trying to sort query in repo by aggregation field. This is a piece of my code:
const queryBuilder = this.createQueryBuilder('article')
.addSelect('min(item.price)', 'minPrice')
.leftJoin('article.items', 'item')
.leftJoin('item.itemInsertions', 'itemInsertion')
.where('article.collectionId = :collectionId', {collectionId: collection.id})
.orderBy('minPrice', 'ASC')
.groupBy('article.code');
As you can see, i need a sorting by minPrice. Then i should add this to “select” section (i can’t add sorting “min(item.price)” without adding to select because there is createOrderByCombinedWithSelectExpression method - it’s looking for alias if it meet “.” symbol - BTW is that correct behaviour?) . OK, doesn’t matter, i’ve added it to select, go further. When i call .getMany() count query is called first. It returns entity id’s array, but you’ve removed groupBy from this query in #313 (groupBy() is called). Then id’s array is incorrect - it returns 1 record in my case because of aggregation function usage. Then the main repository query is called with returned id’s array - so the where clause is incorrect too - “WHERE id IN ($1)”, one id is here in my case, because count query is incorrect. I think that #313 issue was resolved incorrectly - we still need groupBy clause in count query. Sorry if i’m wrong. Thank you!
Regards, Nikolay
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:7 (1 by maintainers)
Top GitHub Comments
Hello, sorry I completely missed that.
I added something like this
@RDeluxe thanks a ton