From 25867071d539343a82fb72157931fdd8cb9f415d Mon Sep 17 00:00:00 2001 From: bin liu Date: Tue, 12 Sep 2023 19:29:04 +0800 Subject: [PATCH] Remove duplicated sort fields from order by clause In MustClone() it will set Sorts field twice, that will generate two duplicated order by fields in the generated SQL. Signed-off-by: bin liu --- src/lib/q/query.go | 1 - src/lib/q/query_test.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/q/query.go b/src/lib/q/query.go index e1bf9c21f05..8910a0e40e9 100644 --- a/src/lib/q/query.go +++ b/src/lib/q/query.go @@ -56,7 +56,6 @@ func MustClone(query *Query) *Query { if query != nil { q.PageNumber = query.PageNumber q.PageSize = query.PageSize - q.Sorts = query.Sorts for k, v := range query.Keywords { q.Keywords[k] = v } diff --git a/src/lib/q/query_test.go b/src/lib/q/query_test.go index 3a76ccff262..e850ccf84c1 100644 --- a/src/lib/q/query_test.go +++ b/src/lib/q/query_test.go @@ -30,6 +30,7 @@ func TestMustClone(t *testing.T) { }{ {"ptr", args{New(KeyWords{"public": "true"})}, New(KeyWords{"public": "true"})}, {"nil", args{nil}, New(KeyWords{})}, + {"sort", args{&Query{Keywords: KeyWords{"public": "true"}, Sorts: []*Sort{NewSort("col-1", true)}}}, &Query{Keywords: KeyWords{"public": "true"}, Sorts: []*Sort{NewSort("col-1", true)}}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {