From 66d3f078291102a30532b6a9d97c757228a9b543 Mon Sep 17 00:00:00 2001 From: chenrui Date: Sat, 5 Mar 2022 17:29:09 +0800 Subject: [PATCH] test: drop table and auto migrate --- tests/preload_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/preload_test.go b/tests/preload_test.go index b18b7d77..9ff706a7 100644 --- a/tests/preload_test.go +++ b/tests/preload_test.go @@ -253,18 +253,24 @@ func TestPreloadGoroutine(t *testing.T) { } 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) } - CheckUser(t, user, user) - var result struct { Something string User } - DB.Model(&User{}).Select("users.*, 'yo' as something").Preload("Account").Find(&result, user.ID) + + 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) }