I have a table that have a hierarchy structure with a parent having many children and a children having many parents.
As an example the following struct:
type User struct {
gorm.Model
Name string
SubUsers []*User `gorm:"many2many:user_sub_users;constraint:OnDelete:CASCADE"`
SuperUsers []*User `gorm:"many2many:user_sub_users.......` // no idea what to fill here
}
What's the gorm configuration I need to add to being able to retrieve the super users (parents) for one entity?
So, as an example, imagine that I have the following
Table users
| ID | name |
--------------=
| 1 | Alice |
| 2 | Bob |
| 3 | Joe |
| 4 | Manuel |
---------------
Table users_sub_users
| ID | user_id | sub_user_id |
-------------------------------
| 1 | 1 | 2 |
| 2 | 1 | 3 |
| 3 | 4 | 1 |
-------------------------------
So if I retrieve the user Alice, I want to get the following:
Alice ->
SubUsers: [Bob, Joe]
SuperUsers: [Manuel]