У меня проблема с ActiveRecords и has_many с именем_класса.
У меня есть эти модели:
main_transaction.rb
class MainTransaction < ApplicationRecord
belongs_to :supplier, :class_name => 'Company'
belongs_to :recipient, :class_name => 'Company'
has_many :invoices
end
invoice.rb
class Invoice < ApplicationRecord
belongs_to :main_transaction
has_one :recipient, :through => :main_transaction, source: :company
end
company.rb
class Company
has_many :main_transactions
has_many :invoices, through: :main_transactions
end
И проблема в том, что, когда я делаю это, выберите в модели счета:
def self.company_filter(companies)
joins(:main_transaction, :recipient).where("companies.company_name IN (?)", companies )
end
Ошибка:
Could not find the source association(s) :company in model MainTransaction. Try 'has_many :recipient, :through => :main_transaction, :source => <name>'. Is it one of supplier, recipient, invoices, main_transaction_elements, or main_transaction_attachments?
Я пробовал много комбинаций, но все еще не работает ...