feat 修复article update select没生效的bug

This commit is contained in:
timerzz 2024-09-06 11:19:59 +08:00
parent a44474b191
commit d24fecebdb
2 changed files with 9 additions and 4 deletions

View File

@ -46,14 +46,13 @@ func (a *articleApi) Upsert(article v2.Article) error {
} }
return nil return nil
}) })
} }
func (a *articleApi) Update(article v2.Article, selects ...string) error { func (a *articleApi) Update(article v2.Article, selects ...string) error {
if len(selects) > 0 { if len(selects) == 0 {
selects = []string{"remark", "exclude"} 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 // ******************Find和List

View File

@ -62,3 +62,9 @@ func TestUpsetArticle(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
} }
func TestArticleApi_Update(t *testing.T) {
db, _ := GetDevDB()
articleApi := NewArticleApi(db)
articleApi.Update(article)
}