You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Broken maximum\minimum queries when default orderBy is defined #11213
import{Column,Entity,Index,PrimaryGeneratedColumn,}from"typeorm";
@Entity({orderBy: {cost: "DESC"}})exportdefaultclassOffer{
@PrimaryGeneratedColumn("uuid")declareid: string;
@Index()
@Column("float",{nullable: false,default: 0})declarecost: number;}// Run this somewhere in your codeawaitrepo.maximum("cost")
My Environment
Dependency
Version
Operating System
Ubuntu 24.04.1 LTS
Node.js version
v20.12.2
Typescript version
5.4.3
TypeORM version
0.3.20
Additional Context
No response
Relevant Database Driver(s)
aurora-mysql
aurora-postgres
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
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, but I don't know how to start. I would need guidance.
Solution I came to is to add .setOption("disable-global-order") inside callAggregateFun from EntityManager
What we have today:
asynccallAggregateFun(entityClass,fnName,columnName,where={}){constmetadata=this.connection.getMetadata(entityClass);constcolumn=metadata.columns.find((item)=>item.propertyPath===columnName);if(!column){thrownewerror_1.TypeORMError(`Column "${columnName}" was not found in table "${metadata.name}"`);}constresult=awaitthis.createQueryBuilder(entityClass,metadata.name).setFindOptions({ where }).select(`${fnName}(${this.connection.driver.escape(column.databaseName)})`,fnName).getRawOne();returnresult[fnName]===null ? null : parseFloat(result[fnName]);}
What I suggest
asynccallAggregateFun(entityClass,fnName,columnName,where={}){constmetadata=this.connection.getMetadata(entityClass);constcolumn=metadata.columns.find((item)=>item.propertyPath===columnName);if(!column){thrownewerror_1.TypeORMError(`Column "${columnName}" was not found in table "${metadata.name}"`);}constresult=awaitthis.createQueryBuilder(entityClass,metadata.name).setFindOptions({ where }).setOption("disable-global-order").select(`${fnName}(${this.connection.driver.escape(column.databaseName)})`,fnName).getRawOne();returnresult[fnName]===null ? null : parseFloat(result[fnName]);}
TypeORM has returned to active development after recently transitioning to new leadership (see related announcement).
As part of the new team's efforts to prioritise work on the project moving forward, it is necessary to clean up the backlog of stale issues.
🧹 This issue is being automatically closed because it has had no activity in the last 6 months.
If you believe this issue is still relevant, feel free to comment below and the maintainers may reopen it. Thank you for your contribution.
Activity
healroot commentedon Dec 30, 2024
The base idea for fix was to remove ordering inside
callAggregateFun, but it leads me to another bug #9902healroot commentedon Dec 31, 2024
Solution I came to is to add
.setOption("disable-global-order")insidecallAggregateFunfromEntityManagerWhat we have today:
What I suggest
github-actions commentedon Sep 17, 2025
TypeORM has returned to active development after recently transitioning to new leadership (see related announcement).
As part of the new team's efforts to prioritise work on the project moving forward, it is necessary to clean up the backlog of stale issues.
🧹 This issue is being automatically closed because it has had no activity in the last 6 months.
If you believe this issue is still relevant, feel free to comment below and the maintainers may reopen it. Thank you for your contribution.
healroot commentedon Sep 18, 2025
It should be an easy fix, which provides value
So I believe its better to keep it in the backlog
gioboa commentedon Sep 18, 2025
Thanks for the heads up @KharchenkoDmitriy
Would you like to try to fix it with a PR?