在活动记录中进行多对多自引用关系的正确方法是什么?

时间:2011-04-27 23:50:41

标签: ruby-on-rails ruby-on-rails-3 activerecord

我有以下有效记录模型:

class Relationship < ActiveRecord::Base  
  belongs_to :user  
  belongs_to :follower, :class_name => 'User', :foreign_key => 'follower_id'  
end  

class User < ActiveRecord::Base  
  has_many :relationships  
  has_many :followers, :through => :relationships  
end  

尝试user.followers时出错     ArgumentError:未知密钥:标识符
    来自/home/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib /active_support/core_ext/hash/keys.rb:43:in`assert_valid_keys'

0 个答案:

没有答案