From d24fecebdb989c97d7484810620f87726e977397 Mon Sep 17 00:00:00 2001 From: timerzz Date: Fri, 6 Sep 2024 11:19:59 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E4=BF=AE=E5=A4=8Darticle=20update=20sel?= =?UTF-8?q?ect=E6=B2=A1=E7=94=9F=E6=95=88=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- structs/storage/article.go | 7 +++---- structs/storage/article_test.go | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/structs/storage/article.go b/structs/storage/article.go index eea0b78..5c4192d 100644 --- a/structs/storage/article.go +++ b/structs/storage/article.go @@ -46,14 +46,13 @@ func (a *articleApi) Upsert(article v2.Article) error { } return nil }) - } func (a *articleApi) Update(article v2.Article, selects ...string) error { - if len(selects) > 0 { - selects = []string{"remark", "exclude"} + if len(selects) == 0 { + selects = []string{"Remark", "Exclude"} } - return a.db.Debug().Select(selects).Updates(article).Error + return a.db.Model(&article).Select(selects).Omit(clause.Associations).Updates(article).Error } // ******************Findĺ’ŚList diff --git a/structs/storage/article_test.go b/structs/storage/article_test.go index 843af14..4513f42 100644 --- a/structs/storage/article_test.go +++ b/structs/storage/article_test.go @@ -62,3 +62,9 @@ func TestUpsetArticle(t *testing.T) { t.Fatal(err) } } + +func TestArticleApi_Update(t *testing.T) { + db, _ := GetDevDB() + articleApi := NewArticleApi(db) + articleApi.Update(article) +}