type Table1 struct {
Id string `gorm:"primary_key"`
Table2s []*Table2 //has many
}
type Table2 struct {
Id string `gorm:"primary_key"
Table1Id string
Table3s []*Table3 `gorm:"many2many:table2_table3"` //many2many
}
type Table3 struct {
Id string `gorm:"primary_key"`
}
如上关系,通过table1的Id怎样查询所有table3与之关联的数据?
期望拿到的数据结构是这样的:
Table1:{
Id:xxx,
Table2s:[
{
Id:xxxxxx,
Table3s:[
{Id:x},
{Id:xx},
...
]
},
...
]
}