title: How to preload with Gorm
body: <p>I am hitting a road block with preloading and associations</p>
  
  <pre><code>type Entity struct {
    ID           uint `gorm:"primary_key"`
    Username     string
    Repositories []*Repository `gorm:"many2many:entity_repositories"`
  }
  
  type Repository struct {
    ID       uint `gorm:"primary_key"`
    Name     string
    Entities []*Entity `gorm:"many2many:entity_repositories"`
  } 
  </code></pre>
  
  <p>With small users numbers the preloading is fine using the below</p>
  
  <pre><code> db.Preload("Repositories").Find(&amp;list)
  </code></pre>
  
  <p>Also tried</p>
  
  <pre><code> db.Model(&amp;User{}).Related(&amp;Repository{}, "Repositories").Find(&amp;list)
  </code></pre>
  
  <p>The preload seems to a <code>select * entities</code> and then a inner join using a <code>SELECT * FROM "repositories" INNER JOIN "entity_repositories" ON "entity_repositories"."repository_id" = "repositories"."id" WHERE ("entity_repositories"."entity_id" IN ('1','2','3','4','5','6','7','8','9','10'))</code></p>
  
  <p>As the number of user's increases this is no longer maintainable as it hits a sqlite limit (dev). I've tried numerous permutations! .. Realistically i guess i just want it to do something like </p>
  
  <pre><code>SELECT entities.*, repositories.*  
  FROM entities 
  JOIN entity_repositories ON entity_repositories.entity_id = entities.id
  JOIN repositories ON repositories.id = entity_repositories.repository_id
  ORDER BY entities.id
  </code></pre>
  
  <p>And fill in the model for me .. </p>
  
  <p>Am I doing something obviously wrong or? </p>