For example, I have the following models
type Company struct {
ID uint `gorm:"PRIMARY_KEY"`
Name string
Departments []*Department `gorm:"FOREIGNKEY:CompanyID"`
Managers []*Manager
}
type Department struct {
ID uint `gorm:"PRIMARY_KEY"`
Name string
Managers []*Manager `gorm:"FOREIGNKEY:DepartmentID"`
CompanyID uint
}
type Manager struct {
ID uint `gorm:"PRIMARY_KEY"`
Name string
DepartmentID uint
}
That is, company has many departments, and department has many managers. How can I create an association between company and manager such that I can say company has many managers through departments?
Is this feature even possible in Go GORM? I am used to seeing this in Rails ActiveRecord
class Company < ApplicationRecord
has_many :departments
has_many :managers, through: :departments
end
Thanks