Is there a way to tell gorm to select only those rows (Attractions), that have a hasOne relation (AttractionsData)? The same as I'd use "::has('relativeName)" in Laravel? The following code will return collection including Attractions with empty relation instead of skipping them
type Attractions struct {
ID uint `gorm:"primary_key"`
...
Active int `json:"-"`
AttractionsData AttractionsData `gorm:"foreignkey:AttractionID"`
}
type AttractionsData struct {
ID uint `gorm:"primary_key"`
AttractionID uint `json:"-"`
Lang string `json:"lang"`
Title string `json:"title"`
Active int `json:"-"`
}
...
func someFunc(c *gin.Context){
...
db := config.DBConnect()
defer db.Close()
var atts []Attractions
db.Preload("AttractionsData", "lang = ? AND active = ?", lang, 1).
Where("country_id = ?", countryID).
Where("category_id = ?", categoryID).
Where("active = ?", 1).
Find(&atts)
...