title: Ruby-on-Rails: Multiple has_many :through possible?
body: <p>Is it possible to have multiple <code>has_many :through</code> relationships that pass through each other in Rails?  I received the suggestion to do so as a solution for another question I posted, but have been unable to get it to work.</p>
  
  <p>Friends are a <strong>cyclic association</strong> through a join table.  The goal is to create a <code>has_many :through</code> for <code>friends_comments</code>, so I can take a <code>User</code> and do something like <code>user.friends_comments</code> to get all comments made by his friends in a single query.</p>
  
  <pre><code>class User
    has_many :friendships
    has_many :friends, 
             :through =&gt; :friendships,
             :conditions =&gt; "status = #{Friendship::FULL}"
    has_many :comments
    has_many :friends_comments, :through =&gt; :friends, :source =&gt; :comments
  end
  
  class Friendship &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :friend, :class_name =&gt; "User", :foreign_key =&gt; "friend_id"
  end
  </code></pre>
  
  <p>This looks great, and makes sense, but isn't working for me.  This is the error I'm getting in relevant part when I try to access a user's friends_comments:<br>
  <code>ERROR:  column users.user_id does not exist<br>
  : SELECT "comments".* FROM "comments"  INNER JOIN "users" ON "comments".user_id = "users".id    WHERE (("users".user_id = 1) AND ((status = 2)))</code></p>
  
  <p>When I just enter user.friends, which works, this is the query it executes:<br>
  <code>: SELECT "users".* FROM "users" INNER JOIN "friendships" ON "users".id = "friendships".friend_id WHERE (("friendships".user_id = 1) AND ((status = 2)))</code></p>
  
  <p>So it seems like it's entirely forgetting about the original <code>has_many</code> through friendship relationship, and then is inappropriately trying to use the User class as a join table.</p>
  
  <p>Am I doing something wrong, or is this simply not possible?</p>