type Language struct {
ID int
Name string
Display string
}
type GameLang struct {
ID int
Game Game2
Lang Language
}
type Game2 struct {
ID int
Name string `sql:"unique";"not null"`
Display string `sql:"not null"`
}
when I
db.CreateTable(&Game2{})
db.CreateTable(&Language{})
db.CreateTable(&GameLang{})
check the game_lang table only ID field created, the game and lang is missing.
I am working with sqlite3 database, anything wrong?
I figured it out
should add an ID field served as reference id and it should be name convention ?
type GameLang struct {
ID int
Game Game2
GameID int64
Lang Language
LangID int64
}
I suggest add this part to doc name convention part
Hi @davyzhang,
This was mentioned in the doc, refer:
type User struct {
ID int
Birthday time.Time
Age int
Name string `sql:"size:255"` // Default size for string is 255, you could reset it with this tag
Num int `sql:"AUTO_INCREMENT"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
Emails []Email // One-To-Many relationship (has many)
BillingAddress Address // One-To-One relationship (has one)
BillingAddressID sql.NullInt64 // Foreign key of BillingAddress
ShippingAddress Address // One-To-One relationship (has one)
ShippingAddressID int // Foreign key of ShippingAddress
IgnoreMe int `sql:"-"` // Ignore this field
Languages []Language `gorm:"many2many:user_languages;"` // Many-To-Many relationship, 'user_languages' is join table
}