title: GORM how to Joins Preloading and user filter as well
body: <p>I'm new in golang and Gorm<br />
  Here is my struct</p>
  <pre><code>type SonModel struct {
   ID int64
   Age int
   Name string
   FatherID int64
   Father FaterModel `gorm:&quot;foreignKey:ID;references:FatherID&quot;`
  }
  
  type FaterModel struct {
   ID int64
   Name string
   GrandID int64
   Grand GrandModel  `gorm:&quot;foreignKey:ID;references:GrandID&quot;`
  }
  
  type GrandModel struct {
   ID int64
   Name string
  }
  </code></pre>
  <p>in raw sql what i want is<br />
  <code>select son.id,son.name,to_json(father.*) father from son join father on father.id = son.father_id where (son.name like '%name%' or father.name like '%name%') and son.age = 15</code><br />
  i want join and filter with father</p>
  <p>in gorm what i'm doing is</p>
  <pre><code>db = db.Joins(&quot;Father&quot;).Preload(&quot;Father.Grand&quot;)
  db = db.Joins(&quot;left join father on father.id = son.id left join grand on grand.id = father.grand_id&quot;)
  db = db.Where(&quot;age = ?&quot;,15)
  db = db.Where(&quot;father.name like ? or son.name like ? or grand.name like ?&quot;,name)
  </code></pre>
  <p>and i found it left join father and grand twice<br />
  first join Father as Father to get father's column<br />
  send is my custom left join<br />
  how can i Joins(&quot;Father&quot;) only one time and use its column to filter</p>