I have a type called appointment
type Appointment struct {
ID int
CourseID int
Course Course
StartTime time.Time
EndTime time.Time
}
That has a BelongsTo relationship with course:
type Course struct {
ID int
DomainID int
Name string
Appointments []Appointment
}
I would like my db query to show an appointment of a course if it exists in the given domain. However, when I do
var appointmentID int
var domainID int
db.Preload("Courses", "domain_id = ?", domainID).Table("appointments").Where("id = ?", appointmentID)
Instead of returning no records found, it returns the appointment but with an uninitialized course field. How should I change the query so I can get the desired result that I am expecting?
Thanks in advance.
Please follow https://github.com/jinzhu/gorm/blob/master/.github/ISSUE_TEMPLATE.md to reopen another issue if it is still a problem for you.
Is this done? I still cannot do it.