feat 修改sellers长度为0不保存的bug

This commit is contained in:
timerzz 2024-09-03 17:32:40 +08:00
parent c4bc3e368a
commit a9a90ab1b4

View File

@ -35,10 +35,15 @@ func (a *articleApi) Upsert(article v2.Article) error {
}).Create(&article).Error; err != nil {
return err
}
if err := tx.Save(&article.Providers).Error; err != nil {
return fmt.Errorf("failed to save providers: %v", err)
if len(article.Providers) > 0 {
if err := tx.Save(&article.Providers).Error; err != nil {
return fmt.Errorf("failed to save providers: %v", err)
}
}
return tx.Save(&article.Sellers).Error
if len(article.Sellers) > 0 {
return tx.Save(&article.Sellers).Error
}
return nil
})
}