fix: duplicate entry in insert transaction
This commit is contained in:
parent
d845824bd8
commit
853bd4c280
1 changed files with 5 additions and 7 deletions
|
@ -23,15 +23,13 @@ type Folder struct {
|
||||||
|
|
||||||
// Create 创建目录
|
// Create 创建目录
|
||||||
func (folder *Folder) Create() (uint, error) {
|
func (folder *Folder) Create() (uint, error) {
|
||||||
tx := DB.Begin()
|
if err := DB.FirstOrCreate(folder, *folder).Error; err != nil {
|
||||||
if err := tx.FirstOrCreate(folder, *folder).Error; err != nil {
|
folder.Model = gorm.Model{}
|
||||||
tx.Rollback()
|
err2 := DB.First(folder, *folder).Error
|
||||||
util.Log().Warning("无法插入目录记录, %s", err)
|
return folder.ID, err2
|
||||||
return 0, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := tx.Commit().Error
|
return folder.ID, nil
|
||||||
return folder.ID, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetChild 返回folder下名为name的子目录,不存在则返回错误
|
// GetChild 返回folder下名为name的子目录,不存在则返回错误
|
||||||
|
|
Loading…
Add table
Reference in a new issue