Skip to content

Commit 44002c1

Browse files
committed
Fix misleading soft delete join test with correct checks
1 parent 71b193d commit 44002c1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tests/joins_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func TestJoinWithSoftDeleted(t *testing.T) {
251251

252252
var user1 User
253253
DB.Model(&User{}).Joins("NamedPet").Joins("Account").First(&user1, user.ID)
254-
if user1.NamedPet == nil || user1.Account.ID == 0 {
254+
if user1.NamedPet.ID == 0 || user1.Account.ID == 0 {
255255
t.Fatalf("joins NamedPet and Account should not empty:%v", user1)
256256
}
257257

@@ -260,17 +260,17 @@ func TestJoinWithSoftDeleted(t *testing.T) {
260260

261261
var user2 User
262262
DB.Model(&User{}).Joins("NamedPet").Joins("Account").First(&user2, user.ID)
263-
if user2.NamedPet == nil || user2.Account.ID != 0 {
264-
t.Fatalf("joins Account should not empty:%v", user2)
263+
if user2.NamedPet.ID == 0 || user2.Account.ID != 0 {
264+
t.Fatalf("joins Account should be empty:%v", user2)
265265
}
266266

267267
// NamedPet should empty
268268
DB.Delete(&user1.NamedPet)
269269

270270
var user3 User
271271
DB.Model(&User{}).Joins("NamedPet").Joins("Account").First(&user3, user.ID)
272-
if user3.NamedPet != nil || user2.Account.ID != 0 {
273-
t.Fatalf("joins NamedPet and Account should not empty:%v", user2)
272+
if user3.NamedPet.ID != 0 || user3.Account.ID != 0 {
273+
t.Fatalf("joins NamedPet and Account should be empty:%v", user3)
274274
}
275275
}
276276

0 commit comments

Comments
 (0)