diff --git a/association_test.go b/association_test.go index e538bbe4..6eb9f773 100644 --- a/association_test.go +++ b/association_test.go @@ -10,9 +10,10 @@ func TestBelongsTo(t *testing.T) { DB.CreateTable(Category{}, Post{}) post := Post{ - Title: "post 1", - Body: "body 1", - Category: Category{Name: "Category 1"}, + Title: "post 1", + Body: "body 1", + Category: Category{Name: "Category 1"}, + MainCategory: Category{Name: "Main Category 1"}, } if err := DB.Save(&post).Error; err != nil { @@ -26,6 +27,12 @@ func TestBelongsTo(t *testing.T) { t.Errorf("Query has one relations with Association") } + var mainCategory Category + DB.Model(&post).Association("MainCategory").Find(&mainCategory) + if mainCategory.Name != "Main Category 1" { + t.Errorf("Query has one relations with Association") + } + var category1 Category DB.Model(&post).Related(&category1) if category1.Name != "Category 1" {