0
활성 레코드에서 자체 참조 관계를 만들기 위해 레일스 캐스트 # 163 http://railscasts.com/episodes/163-self-referential-association에 표시된 자체 참조 모델을 따라 갔지만이 모델은 내가 우정을 작성해야하기 때문에이 모델을 좋아하지 않습니다 및 inverse_friendships는, 그냥 같은 것을 할 수 없었 : 내 person.rb자체 참조 관계 ActiveRecord
class Person
has_many :friendships
has_many :friendships, :foreign_key => "friend_id"
has_many :friends, :through => :friendships
has_many :friends, :through => :friendships, :source => :person
end
에 내 friendship.rb에
을
class Friendship
belongs_to :person
belongs_to :friend, :class_name => "Person"
end
이 질문에 유용한 @apneadiving에서 대답하지 않습니까? http://stackoverflow.com/a/4727419/976775 – MrYoshiji
하하하, 예를 들어 프로젝트를 혼란스럽게합니다. 수정합니다. +1 – OneChillDude