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 关注
- 122 浏览
添加回答
举报