fix(cloudcommon): update db_dispatcher set order by to sqlchemy.SQuery

1. 支持对使用了聚合函数的field进行orderby 操作,如:sum(amount) as
   amount
This commit is contained in:
zhaoxiangchun
2021-10-22 14:28:04 +08:00
parent bfddbaed9a
commit d313c79a43
+8 -6
View File
@@ -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
}
}
}