forked from mirror/gorm
fixed FirstOrCreate not handled error when table is not exists (#5367)
* fixed FirstOrCreate not handled error when table is not exists * delete useless part
This commit is contained in:
parent
7e13b03bd4
commit
dc1ae394f3
|
@ -351,10 +351,10 @@ func (db *DB) FirstOrCreate(dest interface{}, conds ...interface{}) (tx *DB) {
|
|||
}
|
||||
|
||||
return tx.Model(dest).Updates(assigns)
|
||||
}
|
||||
} else {
|
||||
tx.Error = result.Error
|
||||
}
|
||||
}
|
||||
return tx
|
||||
}
|
||||
|
||||
|
|
|
@ -476,6 +476,13 @@ func TestOmitWithCreate(t *testing.T) {
|
|||
CheckUser(t, result2, user2)
|
||||
}
|
||||
|
||||
func TestFirstOrCreateNotExistsTable(t *testing.T) {
|
||||
company := Company{Name: "first_or_create_if_not_exists_table"}
|
||||
if err := DB.Table("not_exists").FirstOrCreate(&company).Error; err == nil {
|
||||
t.Errorf("not exists table, but err is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFirstOrCreateWithPrimaryKey(t *testing.T) {
|
||||
company := Company{ID: 100, Name: "company100_with_primarykey"}
|
||||
DB.FirstOrCreate(&company)
|
||||
|
|
Loading…
Reference in New Issue