clear code syntax

This commit is contained in:
wangjianwen 2022-11-28 10:50:46 +08:00
parent f91313436a
commit eb134bbf33

View File

@ -326,7 +326,12 @@ func (db *DB) FirstOrCreate(dest interface{}, conds ...interface{}) (tx *DB) {
queryTx := db.Session(&Session{}).Limit(1).Order(clause.OrderByColumn{
Column: clause.Column{Table: clause.CurrentTable, Name: clause.PrimaryKey},
})
if result := queryTx.Find(dest, conds...); result.Error == nil {
result := queryTx.Find(dest, conds...)
if result.Error != nil {
tx.Error = result.Error
}
if result.RowsAffected == 0 {
if c, ok := result.Statement.Clauses["WHERE"]; ok {
if where, ok := c.Expression.(clause.Where); ok {
@ -362,9 +367,7 @@ func (db *DB) FirstOrCreate(dest interface{}, conds ...interface{}) (tx *DB) {
return tx.Model(dest).Updates(assigns)
}
} else {
tx.Error = result.Error
}
return tx
}