這是我的律師模型type Lawyer struct { ID uint `gorm:"primaryKey" json:"id"` FirstName string `gorm:"type:varchar(100) not null" json:"first_name"` LastName string `gorm:"type:varchar(100) not null" json:"last_name"` FullName string `gorm:"->;type:text GENERATED ALWAYS AS (concat(first_name,' ',last_name)) VIRTUAL;" json:"full_name"` LocationID uint `gorm:"not null" json:"location_id"` Location Location `gorm:"foreignKey:location_id" json:"location"` Email string `gorm:"unique;not null" json:"email"` Phone string `gorm:"type:varchar(100);not null" json:"phone"` Password string `gorm:"type:varchar(100);not null" json:"password"` ImageURL string `gorm:"type:text" json:"image_url"` Education string `gorm:"not null" json:"education"` Experience uint `gorm:"not null" json:"experience"` PracticeAreas []LawyerPracticeArea `gorm:"foreignKey:LawyerID" json:"practice_areas"` CreatedAt time.Time `gorm:"" json:"created_at"` UpdatedAt time.Time `gorm:"" json:"updated_at"` }最后這是我的 PracticeArea 模型type PracticeArea struct { ID uint `gorm:"primaryKey" json:"practice_area_id"` Name string `gorm:"not null" json:"name"` AvgFee string `gorm:"not null" json:"avg_fee"`}我正在通過這個查詢我的律師模型:-result := db.Preload(clause.Associations).Find(&lawyer)此結果也包含所有 Lawyers 和 LawyerPracticeAreas 數據,但不包含來自 LawyerPracticeAreas 內的 PracticeArea 表的數據。Lawyer 和 PracticeArea 具有多對多關系,而 LawyerPracticeAreas 就是該表。
- 1 回答
- 0 關注
- 130 瀏覽
添加回答
舉報
0/150
提交
取消