fix: duplicate entry in insert transaction

pull/1257/head
HFO4 3 years ago
parent d845824bd8
commit 853bd4c280

@ -23,15 +23,13 @@ type Folder struct {
// Create 创建目录
func (folder *Folder) Create() (uint, error) {
tx := DB.Begin()
if err := tx.FirstOrCreate(folder, *folder).Error; err != nil {
tx.Rollback()
util.Log().Warning("无法插入目录记录, %s", err)
return 0, err
if err := DB.FirstOrCreate(folder, *folder).Error; err != nil {
folder.Model = gorm.Model{}
err2 := DB.First(folder, *folder).Error
return folder.ID, err2
}
err := tx.Commit().Error
return folder.ID, err
return folder.ID, nil
}
// GetChild 返回folder下名为name的子目录不存在则返回错误

Loading…
Cancel
Save