clear code syntax
This commit is contained in:
parent
f91313436a
commit
eb134bbf33
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user