mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(cloudcommon): update db_dispatcher set order by to sqlchemy.SQuery
1. 支持对使用了聚合函数的field进行orderby 操作,如:sum(amount) as amount
This commit is contained in:
@@ -708,12 +708,14 @@ func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.Tok
|
||||
// skip markerField in pagingConf
|
||||
continue
|
||||
}
|
||||
colSpec := manager.TableSpec().ColumnSpec(orderByField)
|
||||
if colSpec != nil {
|
||||
if order == sqlchemy.SQL_ORDER_ASC {
|
||||
q = q.Asc(orderByField)
|
||||
} else {
|
||||
q = q.Desc(orderByField)
|
||||
for _, field := range q.QueryFields() {
|
||||
if orderByField == field.Name() {
|
||||
if order == sqlchemy.SQL_ORDER_ASC {
|
||||
q = q.Asc(field)
|
||||
} else {
|
||||
q = q.Desc(field)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user