Self-referential has_many :through associations

I haven't tested the below, but I was working on something very similar this weekend so, I believe it should work... assuming I understood your questions correctly.

has_many :validated_credentials_as_referee, :foreign_key => 'referee_id', :class_name => 'Credentials', :conditions => 'flag = 1' has_many :validated_referenced_users, :through => :validated_credentials_as_referee

Kad Kerforn wrote:

I wrestled with this previously. Not sure which version of rails you are on, but I had to employ the fixes in bug #6466 (I'm on edge rails).

I also added the extensions stuff to get the << operator working.

has_many :connections,           :foreign_key => 'source_user_id',           :class_name => 'Connection'

has_many :refereeships,           :class_name => 'Connection',           :foreign_key => "source_user_id",           :conditions => "connection_type = 'R'" has_many :referees_out,           :through => :refereeships,           :source => :target_user do        def construct_join_attributes(associate)          super.merge({:connection_type => 'R'})        end      end