Gorm: Can you clarify the where clause for preload?

Created on 4 Mar 2017  路  2Comments  路  Source: go-gorm/gorm

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.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leebrooks0 picture leebrooks0  路  3Comments

hypertornado picture hypertornado  路  3Comments

youtwo123 picture youtwo123  路  3Comments

rfyiamcool picture rfyiamcool  路  3Comments

fieryorc picture fieryorc  路  3Comments