orm/test/relation_test.go
insanity 6b5a02da4a bug
2016-11-09 11:27:59 +09:00

46 lines
712 B
Go

package test
import (
"fmt"
"loafle.com/commons/orm/orm"
_ "loafle.com/commons/orm/orm/dialects/h2"
"testing"
)
type Member struct {
ID int64 `gorm:"primary_key"`
Profile Profile `gorm:"ForeignKey:ProfileID"`
ProfileID int
}
type Profile struct {
ID int64 `gorm:"primary_key"`
Name string
}
func db() *orm.DB {
db, err := orm.Open("h2", "host=192.168.1.215 port=5435 user=sa dbname=ttt sslmode=disable password=qwe123")
if err != nil {
fmt.Println("ERR ", err)
}
db.LogMode(true)
return db
}
func TestBelongTo(t *testing.T) {
db := db()
defer db.Close()
db.CreateTable(&Member{})
db.CreateTable(&Profile{})
m := Member{}
m.Profile.Name = "Geeeeek"
db.Create(&m)
}