From ec11fc7b591f9db1bd381383e968b1193b2f34dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Fri, 24 May 2024 20:18:57 +0800 Subject: [PATCH] fix(region): distinct fields (#20358) --- pkg/cloudcommon/db/modelbase.go | 4 ++-- vendor/yunion.io/x/sqlchemy/query.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/cloudcommon/db/modelbase.go b/pkg/cloudcommon/db/modelbase.go index 5895230ff0..7215f7d9cb 100644 --- a/pkg/cloudcommon/db/modelbase.go +++ b/pkg/cloudcommon/db/modelbase.go @@ -513,7 +513,7 @@ func (manager *SModelBaseManager) GetPropertyDistinctFields(ctx context.Context, result := jsonutils.NewDict() fields := jsonutils.NewArray() if len(input.Field) > 0 { - sq := q.Copy() + sq := q.Copy().ResetFields() // query field for i := 0; i < len(input.Field); i++ { sq = sq.AppendField(sq.Field(input.Field[i])) @@ -536,7 +536,7 @@ func (manager *SModelBaseManager) GetPropertyDistinctFields(ctx context.Context, extraFields := jsonutils.NewArray() if len(input.ExtraResource) > 0 && len(input.ExtraField) > 0 { // query extra field - sq := q.Copy() + sq := q.Copy().ResetFields() em := GetModelManager(input.ExtraResource) if gotypes.IsNil(em) { return nil, httperrors.NewInputParameterError("invalid extra_resource %s", input.ExtraResource) diff --git a/vendor/yunion.io/x/sqlchemy/query.go b/vendor/yunion.io/x/sqlchemy/query.go index e30b46b276..ba72e8214c 100644 --- a/vendor/yunion.io/x/sqlchemy/query.go +++ b/vendor/yunion.io/x/sqlchemy/query.go @@ -50,7 +50,8 @@ type sQueryJoin struct { } // SQuery is a data structure represents a SQL query in the form of -// SELECT ... FROM ... JOIN ... ON ... WHERE ... GROUP BY ... ORDER BY ... HAVING ... +// +// SELECT ... FROM ... JOIN ... ON ... WHERE ... GROUP BY ... ORDER BY ... HAVING ... type SQuery struct { rawSql string fields []IQueryField