Rails has many pass-through errors

I seem to have identified the source as the error message AR suggests, but still receiving errors. Any ideas? Rails 3.2, Ruby 1.9.2

class Document < ActiveRecord::Base has_many :participations has_many :users, :through => :participations has_many :editing_sessions has_many :editors, :through => :editing_sessions, :source => :users end class User < ActiveRecord::Base has_many :participations has_many :documents , :through => :participations has_many :editing_sessions has_many :open_documents, :through => :editing_sessions, :source => :documents end class EditingSession < ActiveRecord::Base belongs_to :users belongs_to :documents end create_table "editing_sessions", :force => true do |t| t.integer "user_id" t.integer "document_id" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end Console: u = User.first => ... OK u.editing_sessions => [] u.open_documents => ActiveRecord::HasManyThroughSourceAssociationNotFoundError: Could not find the source association(s) :document in model EditingSession. Try 'has_many :open_documents, :through => :editing_sessions, :source => <name>'. Is it one of :users or :documents? 
+4
source share
1 answer

Try changing the definition of EditingSession so that label_to is singular:

 class EditingSession < ActiveRecord::Base belongs_to :user belongs_to :document end 

But leave the rest of the source definitions in the Document and Users classes in the plural (i.e :source => :users and :source => :documents )

This is an agreement in the Ruby on Rails Has-Many-Through Guide

+3
source

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


All Articles