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
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.
The text was updated successfully, but these errors were encountered:
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]);}
Issue description
When you define orderBy for entity, its also added to min/max queries which leads to "QueryFailedError"
Expected Behavior
Min/Max queries should not contain "ORDER BY" clause even if entity define the default one
Actual Behavior
Default "ORDER BY" is added to Min/Max queries which leads to "QueryFailedError"
Query example
Steps to reproduce
My Environment
Additional Context
No response
Relevant Database Driver(s)
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.
The text was updated successfully, but these errors were encountered: