fixed FirstOrCreate not handled error when table is not exists
This commit is contained in:
parent
7d1a92d60e
commit
8edc482525
@ -354,6 +354,8 @@ func (db *DB) FirstOrCreate(dest interface{}, conds ...interface{}) (tx *DB) {
|
|||||||
} else {
|
} else {
|
||||||
tx.Error = result.Error
|
tx.Error = result.Error
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
tx.Error = result.Error
|
||||||
}
|
}
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
@ -476,6 +476,13 @@ func TestOmitWithCreate(t *testing.T) {
|
|||||||
CheckUser(t, result2, user2)
|
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) {
|
func TestFirstOrCreateWithPrimaryKey(t *testing.T) {
|
||||||
company := Company{ID: 100, Name: "company100_with_primarykey"}
|
company := Company{ID: 100, Name: "company100_with_primarykey"}
|
||||||
DB.FirstOrCreate(&company)
|
DB.FirstOrCreate(&company)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user