gorm 的预加载怎么才能关掉软删除 type CourseType struct { gorm.Model TypeName string CreatedAt time.Time UpdatedAt time.Time } type Course struct { gorm.Model Title string Price int32 CourseTypeId int32 gorm:"index;unsigned" CourseType CourseType CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time }
/* * @fuc 获取课程 */ func SelectCourse(p map[string]string) (Course, error) { var course Course mydb := db.GetInstance().GetMysqlDB() err := mydb.Debug().Preload("CourseType", func(db *gorm.DB) *gorm.DB { return db.Select("id,type_name") }).Where("id = ?", p["id"]).Find(&course).Error
if err != nil {
return Course{}, errors.New("查询失败")
}
return course, nil
}