0
我很困擾Ruby on Rails關係,我非常感謝你的幫助。如何在Rails中創建follower和followee?
有無模型用戶
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
,但如果要創建新的跟隨者,如:
user.followers << User.first
結果是SystemStackError
謝謝你的幫助!
代替'foreign_key的:「followee_id」'你應該使用'來源:followee' –