Three Columns Join Rails with Active Forest

I have a join table with three columns. I tried to identify three models that have many cross-cutting and hattm. I use active forests only for CRUD functions, after which it will be gradually reduced. I have the feeling that if I need a table with three columns, I will have to first turn off the active scaffold in stages and write a user assistant.

(My husband has many years of experience with SQL, and he agrees that a three-column table is the right approach. He has no experience with rails.)

My three models are: Employee, Project, Role, where the role is the role of employees in the project. My table is employee_projects_roles

What is DRY and an otherwise effective way to do this on rails? If there is a way.

I don't have as much as the commented out habtm and hmt in models and the active scaffold operator in controllers.

[Change] Fun Error: | Obtained using the hmt method in all three main models, as well as in the EmployeeProjectRole model:

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.klass

Extracted source (around line # 5):
2:   <tr>
3:     <%
4:     active_scaffold_config_for(@record.class).subform.columns.each :for => @record, :flatten => true do |column|
5:       next unless in_subform?(column, parent_record) and column_renders_as(column) != :hidden
6:       -%>
7:       <th<%= ' class="required"' if column.required? %>><label><%= column.label %></label></th>
8:     <% end -%>

[Edit 2] Found this article on triple associations (further search on Google using this term is no longer coined). In the main models, I commented on the first line to follow the article:

#    has_many        :employees_projects_roles
    has_many        :roles,     :through => :employees_projects_roles
    has_many        :projects,  :through => :employees_projects_roles

And I got this error:

ActiveRecord::HasManyThroughAssociationNotFoundError in EmployeesController#index
Could not find the association :employees_projects_roles in model Employee

, , active_scaffold, ActiveRecord. , -, , has_many :employees_projects_roles , , . API 2008 ?

+3
4

. :join_table .

"nil object" , . , , .

, .

. SO , , , , , - . , , , , .

0

, , , . ActiveRecord, , , has_many through, .

, . : acl9

, .

+1

employees_projects_roles, has_many: :

  has_many :roles, :through => :employees_projects_role, :source => :employees_projects_roles
  has_many :projects, :through => :employees_projects_role, :source => :employees_projects_roles
0

act_as_activity_loggable, 3 ( 6, ).

, . :

  • Culprit (, , )
  • (, )
  • Activity Loggable (, )

: () () ().

0

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


All Articles