構造体:
type (
User struct{
ID int64
Name string
}
Group struct{
ID int64
Name string
Users []User
}
)
I 挿入幅:
users := []User{}
user := User{ID: int64(1)}
gormConn.First(&user) // .Error is nil, user with ID=1 exists
users = append(users, user)
group := Group{
Name: "Grrr",
Users: users,
}
gormConn.Create(&group)
しかし、私が呼び出すと、代わりにgormConn.Find(&groups)
取得します[{id: 1, name: "Grrr", users: null}]
[{id: 1, name: "Grrr", users: [{id:1, name: "Usr"}]}]
また、SQL テーブルのgroups
列users
が見つかりません。(すべての構造体はgormConn.AutoMigrate
)