0
저는 Ruby on Rails 관계에 상당히 매달렸습니다. 정말 감사드립니다.레일에서 팔로어와 팔로우를 만드는 방법은 무엇입니까?
유무 모델 사용자
class User < ActiveRecord::Base
has_many :followers, :through => :follows, foreign_key: "followee_id"
has_many :followees, :through => :follows, foreign_key: "follower_id"
end
및 모델
class Follow < ActiveRecord::Base
belongs_to :followee, class_name: "User"
belongs_to :follower, class_name: "User"
end
에 따라하지만, 경우처럼 새로운 추종자를 만들 : 결과가 SystemStackError입니다
user.followers << User.first
도움 주셔서 감사합니다.
다음class User < ActiveRecord::Base
has_many :follower_follows, foreign_key: :followee_id, class_name: "Follow"
has_many :followers, through: :follower_follows, source: :follower
has_many :followee_follows, foreign_key: :follower_id, class_name: "Follow"
has_many :followees, through: :followee_follows, source: :followee
end
이 follower_follows 및 followee_follows 테이블 및 소스에 가입되어 있습니다 : 추종자가 belong_to와 일치 : 추종자 식별을 따르 모델과 소스 :
: 당신은 소스'사용해야합니다' "followee_id": followee' –