From 6b5a02da4a54f22e8c80b4c45bdea61d9e3156e9 Mon Sep 17 00:00:00 2001 From: insanity Date: Wed, 9 Nov 2016 11:27:59 +0900 Subject: [PATCH] bug --- test/insert_test.go | 2 +- test/relation_test.go | 44 +++++++++++++++++++++++++++++++++++++++++++ test/typedef_test.go | 10 +++++++--- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/test/insert_test.go b/test/insert_test.go index 138f883..efdab35 100644 --- a/test/insert_test.go +++ b/test/insert_test.go @@ -28,7 +28,7 @@ func TestH2Insert(t *testing.T) { db.CreateTable(&Animal{}) - ani := Animal{Types: "CAT", Name: "CATIA"} + ani := Animal{Types: "ELE", Name: "CATIA"} db.Create(&ani) diff --git a/test/relation_test.go b/test/relation_test.go index 56e5404..ae8f8d9 100644 --- a/test/relation_test.go +++ b/test/relation_test.go @@ -1 +1,45 @@ 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) + +} diff --git a/test/typedef_test.go b/test/typedef_test.go index 6a77401..1f8f0ff 100644 --- a/test/typedef_test.go +++ b/test/typedef_test.go @@ -27,18 +27,22 @@ Many to Many Ignore `gorm:"-"` + +Default +`gorm:"default:'ItIsTheDefaultValue'"` + */ package test import ( "database/sql" - "github.com/jinzhu/gorm" + "loafle.com/commons/orm/orm" "time" ) type User struct { - gorm.Model + orm.Model Birthday time.Time Age int @@ -79,7 +83,7 @@ type Language struct { } type CreditCard struct { - gorm.Model + orm.Model UserID uint Number string }