From d313c79a43368dc7e0cc763897d9b649544a9d02 Mon Sep 17 00:00:00 2001 From: zhaoxiangchun <1422928955@qq.com> Date: Fri, 22 Oct 2021 14:15:09 +0800 Subject: [PATCH] fix(cloudcommon): update db_dispatcher set order by to sqlchemy.SQuery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 支持对使用了聚合函数的field进行orderby 操作,如:sum(amount) as amount --- pkg/cloudcommon/db/db_dispatcher.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/cloudcommon/db/db_dispatcher.go b/pkg/cloudcommon/db/db_dispatcher.go index b3fef8f8a2..5c85bd7932 100644 --- a/pkg/cloudcommon/db/db_dispatcher.go +++ b/pkg/cloudcommon/db/db_dispatcher.go @@ -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 } } }