例如,我有以下模型
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
}
也就是说,公司有很多部门,部门有很多管理人员。如何在公司和经理之间建立联系,以便我可以说公司通过部门有很多经理?
Go GORM中是否可以使用此功能?我习惯在Rails ActiveRecord中看到这个
class Company < ApplicationRecord
has_many :departments
has_many :managers, through: :departments
end
由于