找不到源关联:在模型关系中跟随。

时间:2015-07-05 19:54:37

标签: ruby-on-rails

我正在关注Michael Hartl的rails book并收到以下错误消息:

python -m SimpleHTTPServer

调用ActiveRecord::HasManyThroughSourceAssociationNotFoundError: Could not find the source association(s) :follower in model Relationship. Try 'has_many :following, :through => :active_relationships, :source => <name>'. Is it one of ? 时(其中michael.follower是用户对象)。

以下是关联:

michael

1 个答案:

答案 0 :(得分:0)

如果我理解正确,你会通过关系模型在用户和关系模型之间建立多对多的关系(我很抱歉同义词)。

我建议改变

has_many :following, :through => :active_relationships, source: :follower
has_many :followers, :through => :passive_relationships, source: :followed

has_many :following, :through => :active_relationships, class_name: "User"
has_many :followers, :through => :passive_relationships, class_name: "User"
相关问题