title: Golang gorm preloading
body: <p>I'm writing my first app in golang, so sorry for newbie question, but I wasn't able to find the solution for the following problem:</p>
  
  <p>I have two tables, <strong>position</strong> and <strong>attachment</strong>. Each position can have multiple attachments. Here is my model:</p>
  
  <pre><code>type Positions struct {
      Sys_id     int `gorm:"AUTO_INCREMENT" gorm:"column:sys_id" json:"sys_id,omitempty"`
      Name string `gorm:"size:120" gorm:"column:name" json:"name,omitempty"`
      OpenPositions int `gorm:"column:open_positions" json:"open_positions,omitempty"`
      ContactList string `gorm:"size:1000" gorm:"column:contact_list" json:"contact_list,omitempty"`
      Attachments []Attachment `gorm:"ForeignKey:RecordId"`
  }
  
  type Attachment struct {
      Sys_id     int `gorm:"AUTO_INCREMENT" gorm:"column:sys_id" json:"sys_id"`
      Name string `gorm:"size:255" gorm:"column: name" json:"name"`
      File string `gorm:"size:255" gorm:"column:file" json:"file"`
      RecordId int `gorm:"column:record_id" json:"record_id"`
      Table string `gorm:"size:255" gorm:"column:table" json:"table"`
      // ...
  }
  </code></pre>
  
  <p>I want to query the db and get <strong>positions</strong> with <strong>attachments</strong></p>
  
  <pre><code>positions2 := []models.Positions{}
  err := db.Where("open_positions &gt; ?", 0).Preload("Attachments", "`table` = ?", "user_position").Find(&amp;positions2)
  if err != nil {
      log.WithFields(log.Fields{
          "type": "queryerr",
          "msg": err,
      }).Error("faked up query")
  }
  </code></pre>
  
  <p>Result of this query - I get positions correctly but the attachments are empty.</p>
  
  <blockquote>
    <p>(can't preload field Attachments for models.Positions)
        level=error msg="faked up query" msg=&amp;{0xc04200aca0 can't preload field Attachments for models.Positions 6  0xc042187e40 0xc042187d90 0xc0422cd4a0 0 {0xc042225130}  false  map[] map[] false}</p>
  </blockquote>
  
  <p>Thanks in advance for help</p>