title: Gorm left join with Scan()
body: <p>I am trying to join to tables <code>Class</code> and <code>Booking</code> on <code>classes.id = bookings.class_id</code> and get the result of the type <code>DisplayBooking</code></p>
  <pre><code>type Class struct {
      Id   int    `json:&quot;id&quot;`
      Name string `json:&quot;name&quot;`
  }
  
  type Booking struct {
      Id      int    `json:&quot;id&quot;`
      User    string `json:&quot;user&quot;`
      Members int    `json:&quot;members&quot;`
      ClassId int    `json:classid`
      //Class   Class  `gorm:&quot;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;&quot;`
  }
  type DisplayBooking struct {
      Id        int    `json:&quot;id&quot;`
      User      string `json:&quot;user&quot;`
      Members   int    `json:&quot;members&quot;`
      ClassId   int    `json:classid`
      ClassName string `json:&quot;classname&quot;`
  }
  </code></pre>
  <p>To do that I tried gorm's <code>Scan()</code> and <code>Rows()</code> methods</p>
  <pre><code>func returnAllBookings(w http.ResponseWriter, r *http.Request) {
      bookings := []DisplayBooking{}
  
      db.Model(&amp;Booking{}).Select(&quot;bookings.id, bookings.user, bookings.members, bookings.class_id, classes.name&quot;).Joins(&quot;left join classes on bookings.class_id = classes.id&quot;).Scan(&amp;bookings)
  
      fmt.Println(&quot;Endpoint Hit: returnAllBookings&quot;)
  
      rows, err := db.Table(&quot;bookings&quot;).Select(&quot;bookings.id, bookings.user, bookings.members, bookings.class_id, classes.name&quot;).Joins(&quot;left join classes on bookings.class_id = classes.id&quot;).Rows()
      if err != nil {
          return
      }
  
      for rows.Next() {
          log.Println(rows)
      }
      json.NewEncoder(w).Encode(bookings)
  }
  </code></pre>
  <p><code>Scan()</code> return null values in class_name field, and while <code>Rows()</code> seems to do the job the output format is not a JSON encoding
  <code>Scan()</code> output</p>
  <pre><code>[{&quot;id&quot;:1,&quot;user&quot;:&quot;test1&quot;,&quot;members&quot;:1,&quot;ClassId&quot;:2,&quot;classname&quot;:&quot;&quot;},{&quot;id&quot;:2,&quot;user&quot;:&quot;test2&quot;,&quot;members&quot;:2,&quot;ClassId&quot;:1,&quot;classname&quot;:&quot;&quot;}]
  </code></pre>
  <p><code>Rows()</code> output (console) - bold values are correct, but there's a lot of unnecessary information</p>
  <pre><code>my-go-app_1  | 2021/04/09 07:42:09 &amp;{0xc00021e1b0 0x6dcfa0 0xc00026adc0 &lt;nil&gt; &lt;nil&gt; {{0 0} 0 0 0 0} false &lt;nil&gt; **[1 test1 1 2 business]**}
  my-go-app_1  | 2021/04/09 07:42:09 &amp;{0xc00021e1b0 0x6dcfa0 0xc00026adc0 &lt;nil&gt; &lt;nil&gt; {{0 0} 0 0 0 0} false &lt;nil&gt; **[2 test2 2 1 first]**}
  </code></pre>
  <p>Is there a way to make the code work with <code>Scan()</code> function?</p>