我有以下人为的例子:
type Top struct {
ID uint `gorm:"primary_key"`
Name string
Middle []*Middle
}
type Middle struct {
ID uint `gorm:"primary_key"`
TopID int
Name string
Low []*Low
}
type Low struct {
ID uint `gorm:"primary_key"`
MiddleID int
Name string
Bottom []*Bottom
}
type Bottom struct {
ID uint `gorm:"primary_key"`
LowID int
Name string
}
top := Top{
Name: "Top",
Middle: []*Middle{
{
Name: "Middle",
Low: []*Low{
{
Name: "Low",
Bottom: []*Bottom{
{
Name: "Bottom",
},
},
},
},
},
},
} …Run Code Online (Sandbox Code Playgroud)