1 回答

TA貢獻1836條經驗 獲得超4個贊
根據表名的假設,您需要在此處處理幾件事。tt_historique
按照慣例,go-gorm 在構造 SQL 查詢時使用復數 snake case 結構名稱作為數據庫表。在您的情況下,要預加載字段,它將查找表。Historique []Historiquehistoriques
要覆蓋它,您需要實現接口:Tabler
type Patient struct {
gorm.Model
Prenom string `json:"prenom" gorm:"column:patient_prenom"`
Nom string `json:"nom" gorm:"column:patient_nom"`
Genre string `json:"genre" gorm:"column:patient_genre"`
Naissance string `json:"naissance" gorm:"column:patient_naissance"`
Historique []Historique `gorm:"foreignKey:Fk_patient_id"`
}
type Historique struct {
Fk_patient_id string
Date_consultation string
Fk_maladie_id uint
Fk_compte_medecin_id uint
Patient Patient
}
func (Historique) TableName() string {
return "tt_historique"
}
然后,您的查詢將如下所示:
db := GetDB().Preload("Historique").Find(patient)
- 1 回答
- 0 關注
- 108 瀏覽
添加回答
舉報