Hi I'm having trouble conceptualizing when to use :source
and when to use :class
for my more complex models.
Here I have an example of users with friends.
class User < ActiveRecord::Base
...
has_many :friendships, :dependent => :destroy
has_many :friends, :through => :friendships, :conditions => "status = 'accepted'"
has_many :requested_friends, :through => :friendships, :source => :friend, :conditions => "status = 'requested'", :order => :created_at
has_many :pending_friends, :through => :friendships, :source => :friend, :conditions => "status = 'pending'", :order => :created_at
end
class Friendship < ActiveRecord::Base
attr_accessible :friend_id, :user_id, :status
belongs_to :user
belongs_to :friend, :class_name => "User", :foreign_key => 'friend_id'
end
Can someone explain why for Friendship it's :class_name
instead of :source
? Is this because that's just the pairing (has_many + :source , belongs_to + :class_name)?