在活动记录中进行多对多自引用关系的正确方法是什么?
我有以下活动记录模型:
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'
I have the following active record models:
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
I get an error when I try user.followers.
ArgumentError: Unknown key(s): identifier
from /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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论