title: GORM Preload by condition in a related table
body: <p>I can't figure how to properly write a query that will select only those entries where condition is applied against relations table.
  My many-to-many schema looks like this <code>Topics</code> - <code>TopicPosts</code> - <code>Posts</code>. I want to query all <code>TopicPosts</code> where <code>Post</code> is not private or is belongs to the current user. I'm doing it like this: </p>
  
  <pre><code>topicPosts := []model.TopicPost{}
  h.DB.
      Where("topic_id = ?", id).
      Preload("Post", func(db *gorm.DB) *gorm.DB {
          return db.Not("is_private = ? AND user_id != ?", "true", currentUser.ID)
      }).
      Preload("Post.Tags").
      Find(&amp;topicPosts)
  </code></pre>
  
  <p>As expected it returns all <code>TopicPosts</code> but does not eagerly load <code>Posts</code> with a given condition. I then manually filter them out:</p>
  
  <pre><code>publicTopicPosts := []model.TopicPost{}
  for _, p := range topicPosts {
      if p.Post.ID != 0 {
          publicTopicPosts = append(publicTopicPosts, p)
      }
  }
  </code></pre>
  
  <p>I realise this is a subpar solution, I'm not very good with SQL but I think it should be possible to achieve within a single query. I would appreciate any help. I'm using Postgres if it matters.</p>