title: ActiveRecord joining nested associations on non default values
body: <p>Before you ask, I have no control over creating any views or join tables in the database I'm working with.</p>
  
  <p>I found in the ActiveRecord docs where you can do multi-level joining:    </p>
  
  <pre><code>12.2.4 Joining Nested Associations (Multiple Level)
  
  Category.joins(articles: [{ comments: :guest }, :tags])
  This produces:
  
  SELECT categories.* FROM categories
    INNER JOIN articles ON articles.category_id = categories.id
    INNER JOIN comments ON comments.article_id = articles.id
    INNER JOIN guests ON guests.comment_id = comments.id
    INNER JOIN tags ON tags.article_id = articles.id
  </code></pre>
  
  <p>And where you can specify what to join on </p>
  
  <pre><code>Client.joins('LEFT OUTER JOIN addresses ON addresses.client_id = clients.id')
  </code></pre>
  
  <p>What I want to do is something that combines the 2</p>
  
  <pre><code>Client.joins('Inner Join addresses on addresses.client_name = client.name').joins('Inner Join state on state.abreviation = addresses.state_abreviation)
  </code></pre>
  
  <p>or in raw sql</p>
  
  <pre><code>Select client.* from client 
  Inner Join addresses on client.client_name = addresses.client_name
  Inner Join state on addresses.state_abreviation = state.abreviation
  </code></pre>
  
  <p>and If I can do this using associations instead of joins that would be great!:</p>
  
  <pre><code>class Category &lt; ActiveRecord::Base
    has_many :articles
  end
  
  class Article &lt; ActiveRecord::Base
    belongs_to :category
    has_many :comments
    has_many :tags
  end
  
  class Comment &lt; ActiveRecord::Base
    belongs_to :article
    has_one :guest
  end
  
  class Guest &lt; ActiveRecord::Base
    belongs_to :comment
  end
  
  class Tag &lt; ActiveRecord::Base
    belongs_to :article
  end
  </code></pre>