mirror of https://github.com/go-gorm/gorm.git
26 lines
621 B
Go
26 lines
621 B
Go
|
package tests_test
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
. "github.com/jinzhu/gorm/tests"
|
||
|
)
|
||
|
|
||
|
func TestUpdateBelongsTo(t *testing.T) {
|
||
|
var user = *GetUser("update-belongs-to", Config{})
|
||
|
|
||
|
if err := DB.Create(&user).Error; err != nil {
|
||
|
t.Fatalf("errors happened when create: %v", err)
|
||
|
}
|
||
|
|
||
|
user.Company = Company{Name: "company-belongs-to-association"}
|
||
|
user.Manager = &User{Name: "manager-belongs-to-association"}
|
||
|
if err := DB.Save(&user).Error; err != nil {
|
||
|
t.Fatalf("errors happened when update: %v", err)
|
||
|
}
|
||
|
|
||
|
var user2 User
|
||
|
DB.Preload("Company").Preload("Manager").Find(&user2, "id = ?", user.ID)
|
||
|
CheckUser(t, user2, user)
|
||
|
}
|