Rails-Belongs_to 在同一个表中
我有一个用户表,每个用户都有另一个用户,他们必须“杀死”关联,如下所示。
class User < ActiveRecord::Base
belongs_to(:user_to_kill, :class_name => :User)
但是,当我进行以下调用时:
@current_user.user_to_kill.screen_name
它返回以下错误和堆栈跟踪
NameError: uninitialized constant User::User
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.0.3/lib/active_record/base.rb:1199:in `compute_type'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.0.3/lib/active_record/reflection.rb:162:in `klass'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.0.3/lib/active_record/associations/belongs_to_association.rb:59:in `find_target'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.0.3/lib/active_record/associations/association_proxy.rb:237:in `load_target'
提前感谢您的帮助。
I have a table of users and each user has another user that they have to "kill" the association is written as follows.
class User < ActiveRecord::Base
belongs_to(:user_to_kill, :class_name => :User)
However when I make the following call:
@current_user.user_to_kill.screen_name
It returns the following error and stack trace
NameError: uninitialized constant User::User
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.0.3/lib/active_record/base.rb:1199:in `compute_type'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.0.3/lib/active_record/reflection.rb:162:in `klass'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.0.3/lib/active_record/associations/belongs_to_association.rb:59:in `find_target'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.0.3/lib/active_record/associations/association_proxy.rb:237:in `load_target'
Thanks in advance for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其更改为:
Change it to :