加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 未找到名为的协会

发布时间:2020-12-17 02:36:58 所属栏目:百科 来源:网络整理
导读:我在Rails 2中工作.我有三个表:users,lms_users和group_details. 在lms_users中,来自用户的id和group_details将作为外键出现. lms_users也有自己的属性.我无法在各自的模型中定义关联.我试过这个: 在LmsUser模型中 belongs_to :usersbelongs_to :group_det
我在Rails 2中工作.我有三个表:users,lms_users和group_details.

在lms_users中,来自用户的id和group_details将作为外键出现. lms_users也有自己的属性.我无法在各自的模型中定义关联.我试过这个:

在LmsUser模型中

belongs_to :users
belongs_to :group_details

在用户模型中

has_many :group_details,:through => :lms_users

在GroupDetail模型中

has_many :users,:through => :lms_users

但是我收到了这个错误

ActiveRecord::ConfigurationError in Lms usersController#index
Association named 'lms_user' was not found; perhaps you misspelled it?

解决方法

您需要将您正在经历的关联添加为has_many.

例如,您的user.rb应如下所示:

has_many :lms_users
has_many :group_details,:through => :lms_users

您的group_detail.rb应包含以下内容:

has_many :lms_users
has_many :users,:through => :lms_users

:通过一个关联,所以关联需要已经建立.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读