bug
This commit is contained in:
parent
e763dee703
commit
6b5a02da4a
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user