(t *testing.T)
| 317 | } |
| 318 | |
| 319 | func TestAssociationEmptyQueryClause(t *testing.T) { |
| 320 | type Organization struct { |
| 321 | gorm.Model |
| 322 | Name string |
| 323 | } |
| 324 | type Region struct { |
| 325 | gorm.Model |
| 326 | Name string |
| 327 | Organizations []Organization `gorm:"many2many:region_orgs;"` |
| 328 | } |
| 329 | type RegionOrg struct { |
| 330 | RegionId uint |
| 331 | OrganizationId uint |
| 332 | Empty myType |
| 333 | } |
| 334 | if err := DB.SetupJoinTable(&Region{}, "Organizations", &RegionOrg{}); err != nil { |
| 335 | t.Fatalf("Failed to set up join table, got error: %s", err) |
| 336 | } |
| 337 | if err := DB.Migrator().DropTable(&Organization{}, &Region{}); err != nil { |
| 338 | t.Fatalf("Failed to migrate, got error: %s", err) |
| 339 | } |
| 340 | if err := DB.AutoMigrate(&Organization{}, &Region{}); err != nil { |
| 341 | t.Fatalf("Failed to migrate, got error: %v", err) |
| 342 | } |
| 343 | region := &Region{Name: "Region1"} |
| 344 | if err := DB.Create(region).Error; err != nil { |
| 345 | t.Fatalf("fail to create region %v", err) |
| 346 | } |
| 347 | var orgs []Organization |
| 348 | |
| 349 | if err := DB.Model(&Region{}).Association("Organizations").Find(&orgs); err != nil { |
| 350 | t.Fatalf("fail to find region organizations %v", err) |
| 351 | } else { |
| 352 | AssertEqual(t, len(orgs), 0) |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | type AssociationEmptyUser struct { |
| 357 | ID uint |
nothing calls this directly
no test coverage detected