title: Phoenix: has_many through with conditions
body: <p>I have following models:</p>
  
  <pre><code>defmodule My.User do
    use My.Web, :model
  
    schema "users" do
      has_many :relationships, My.Relationship
      has_many :pending_friends, through: [:relationships, :friend]
      has_many :rejected_friends, through: [:relationships, :friend]
      has_many :friends, through: [:relationships, :friend]
      has_many :suggested_friends, through: [:relationships, :friend]
  
      timestamps()
    end
  end
  
  
  defmodule My.Relationship do
    use My.Web, :model
  
    schema "relationships" do
      belongs_to :user, My.User
      belongs_to :friend, My.User
      field :type, :integer
  
      timestamps()
    end
  end
  </code></pre>
  
  <p>Basically, user can have relationships with other users of different types.
  My issue is that I am not able to preload the data correctly.</p>
  
  <p>I was trying to find a way to either add constraint to "has_many" or write a query, which maps "relationships" data to 4 types, i.e. via "select" but nothing seems to work.</p>