Merge remote-tracking branch 'origin/master'

This commit is contained in:
snoop 2016-11-09 15:58:58 +09:00
commit 8e2dcd6a41
3 changed files with 52 additions and 4 deletions

View File

@ -28,7 +28,7 @@ func TestH2Insert(t *testing.T) {
db.CreateTable(&Animal{}) db.CreateTable(&Animal{})
ani := Animal{Types: "CAT", Name: "CATIA"} ani := Animal{Types: "ELE", Name: "CATIA"}
db.Create(&ani) db.Create(&ani)

View File

@ -1 +1,45 @@
package test 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)
}

View File

@ -27,18 +27,22 @@ Many to Many
Ignore Ignore
`gorm:"-"` `gorm:"-"`
Default
`gorm:"default:'ItIsTheDefaultValue'"`
*/ */
package test package test
import ( import (
"database/sql" "database/sql"
"github.com/jinzhu/gorm" "loafle.com/commons/orm/orm"
"time" "time"
) )
type User struct { type User struct {
gorm.Model orm.Model
Birthday time.Time Birthday time.Time
Age int Age int
@ -79,7 +83,7 @@ type Language struct {
} }
type CreditCard struct { type CreditCard struct {
gorm.Model orm.Model
UserID uint UserID uint
Number string Number string
} }