Я сталкиваюсь странные ошибки с ActiveRecord 3.2.8 с этим кодом:ActiveRecord 3.2.8 ассоциации ошибки
У меня есть 2 модели - клиента и счета-фактуры.
class Customer < ActiveRecord::Base
has_many :invoices
end
class Invoice < ActiveRecord::Base
belongs_to :customer
def self.last(customer)
customer.invoices.order("some_date_column DESC").first
end
end
Я бегу код, подобный этому:
Thread.new do
ActiveRecord::Base.connection_pool.with_connection do
Customer.all.each do |customer|
invoice = Invoice.last(customer)
...
end
end
end
При выполнении этого кода я иногда получаю следующую странную ошибку:
/var/lib/gems/1.8/gems/activerecord-3.2.8/lib/active_record/associations/collection_association.rb:25:in 'initialize': wrong number of arguments (1 for 0) (ArgumentError)
from /var/lib/gems/1.8/gems/activerecord-3.2.8/lib/active_record/associations/collection_association.rb:25:in 'new'
from /var/lib/gems/1.8/gems/activerecord-3.2.8/lib/active_record/associations/collection_association.rb:25:in 'initialize'
from /var/lib/gems/1.8/gems/activerecord-3.2.8/lib/active_record/associations.rb:157:in 'new'
from /var/lib/gems/1.8/gems/activerecord-3.2.8/lib/active_record/associations.rb:157:in 'association'
from /var/lib/gems/1.8/gems/activerecord-3.2.8/lib/active_record/associations/builder/association.rb:44:in 'invoices'
from .../models/invoice.rb:7:in 'last'
Любая помощь очень ценится.
Спасибо, но, как вы можете видеть в определении метода, метод Invoice.last должен принимать ровно 1 аргумент. АргументError был поднят в файле collection_association.rb ActiveRecords в строке 25 при вызове метода new. – Igi