Association was not found

I work in Rails 2. I have three tables: users , lms_users and group_details .

In lms_users id of users and group_details comes in as foreign keys. lms_users has its own attributes. I cannot determine the association in their respective models. I tried this:

In the model LmsUser

 belongs_to :users belongs_to :group_details 

In User model

 has_many :group_details , :through => :lms_users 

In the model GroupDetail

 has_many :users , :through => :lms_users 

But I get this error

 ActiveRecord::ConfigurationError in Lms usersController#index Association named 'lms_user' was not found; perhaps you misspelled it? 
+4
source share
1 answer

You need to add the association you are going with as has_many.

So, for example, your user.rb should look like this:

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

And your group_detail.rb should contain the following:

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

: through the union, so the association should already be configured.

+5
source

Source: https://habr.com/ru/post/1434146/


All Articles