mirror of https://github.com/go-gorm/gorm.git
Test HasOne relations for normal foreign key or scanner
This commit is contained in:
parent
affb64b04b
commit
715d7951aa
|
@ -13,6 +13,7 @@ func TestBelongsTo(t *testing.T) {
|
|||
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" {
|
||||
|
|
Loading…
Reference in New Issue