(t *testing.T)
| 1348 | } |
| 1349 | |
| 1350 | func TestNilPointerSlice2(t *testing.T) { |
| 1351 | type ( |
| 1352 | Level4 struct { |
| 1353 | ID uint |
| 1354 | } |
| 1355 | Level3 struct { |
| 1356 | ID uint |
| 1357 | Level4ID sql.NullInt64 `sql:"index"` |
| 1358 | Level4 *Level4 |
| 1359 | } |
| 1360 | Level2 struct { |
| 1361 | ID uint |
| 1362 | Level3s []*Level3 `gorm:"many2many:level2_level3s"` |
| 1363 | } |
| 1364 | Level1 struct { |
| 1365 | ID uint |
| 1366 | Level2ID sql.NullInt64 `sql:"index"` |
| 1367 | Level2 *Level2 |
| 1368 | } |
| 1369 | ) |
| 1370 | |
| 1371 | DB.Migrator().DropTable(&Level3{}, &Level2{}, &Level1{}, &Level4{}) |
| 1372 | |
| 1373 | if err := DB.AutoMigrate(new(Level4), new(Level3), new(Level2), new(Level1)); err != nil { |
| 1374 | t.Error(err) |
| 1375 | } |
| 1376 | |
| 1377 | want := new(Level1) |
| 1378 | if err := DB.Save(want).Error; err != nil { |
| 1379 | t.Error(err) |
| 1380 | } |
| 1381 | |
| 1382 | got := new(Level1) |
| 1383 | err := DB.Preload("Level2.Level3s.Level4").Last(&got).Error |
| 1384 | if err != nil { |
| 1385 | t.Error(err) |
| 1386 | } |
| 1387 | |
| 1388 | if !reflect.DeepEqual(got, want) { |
| 1389 | t.Errorf("got %s; want %s", toJSONString(got), toJSONString(want)) |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | func TestPrefixedPreloadDuplication(t *testing.T) { |
| 1394 | type ( |
nothing calls this directly
no test coverage detected