Код: Выделить всё
type struct UserInfo{
Name string `json:"name"`
Age int `json:"age"`
}
type struct Profile{
ID string `json:"id"`
User *UserInfo `json:"user"`
UserType string `json:"user_type"`
}
Код: Выделить всё
CREATE TABLE `profile`{
`id` varchar(24) NOT NULL,
`user` json DEFAULT NULL,
`user_type` varchar(24) DEFAULT NULL
}
< /code>
Вот мой код: < /p>
var profile Profile
Profile.ID = "Demo~1"
Profile.UserType = "Permanent"
Profile.User = &User {
Name: "John",
Age: 24,
}
if err:= db.Create(&profile).Error; err != nil {
fmt.Errorf("Unsuccessful insert")
}
может кто -нибудь помочь?
Подробнее здесь: https://stackoverflow.com/questions/795 ... using-gorm
Мобильная версия