forked from mirror/gorm
test: fix test fail
This commit is contained in:
parent
66d3f07829
commit
40cbba49f3
|
@ -13,6 +13,25 @@ import (
|
|||
. "gorm.io/gorm/utils/tests"
|
||||
)
|
||||
|
||||
// https://github.com/go-gorm/gorm/issues/4886
|
||||
func TestPreloadWithDiffModel(t *testing.T) {
|
||||
user := *GetUser("preload_with_diff_model", Config{Account: true})
|
||||
|
||||
if err := DB.Create(&user).Error; err != nil {
|
||||
t.Fatalf("errors happened when create: %v", err)
|
||||
}
|
||||
|
||||
var result struct {
|
||||
Something string
|
||||
User
|
||||
}
|
||||
|
||||
DB.Model(User{}).Preload("Account", clause.Eq{Column: "number", Value: user.Account.Number}).Select(
|
||||
"users.*, 'yo' as something").First(&result, "name = ?", user.Name)
|
||||
|
||||
CheckUser(t, user, result.User)
|
||||
}
|
||||
|
||||
func TestPreloadWithAssociations(t *testing.T) {
|
||||
user := *GetUser("preload_with_associations", Config{
|
||||
Account: true,
|
||||
|
@ -251,26 +270,3 @@ func TestPreloadGoroutine(t *testing.T) {
|
|||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestPreloadWithDiffModel(t *testing.T) {
|
||||
DB.Migrator().DropTable(&User{}, &Account{})
|
||||
if err := DB.AutoMigrate(&User{}, &Account{}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
user := *GetUser("preload_with_diff_model", Config{Account: true})
|
||||
|
||||
if err := DB.Create(&user).Error; err != nil {
|
||||
t.Fatalf("errors happened when create: %v", err)
|
||||
}
|
||||
|
||||
var result struct {
|
||||
Something string
|
||||
User
|
||||
}
|
||||
|
||||
DB.Model(User{}).Preload("Account", clause.Eq{Column: "number", Value: user.Account.Number}).Select(
|
||||
"users.*, 'yo' as something").First(&result, "name = ?", user.Name)
|
||||
|
||||
CheckUser(t, user, result.User)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue