こんにちは、より複雑なモデルを:source
いつ使用するか、いつ使用するかを概念化するのに苦労しています。:class
ここに、友達がいるユーザーの例があります。
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
:class_name
誰かが友情の代わりになぜそれを説明できますか:source
? これはペアリング (has_many + :source 、 belongs_to + :class_name) だけだからですか?