我在 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'
任何帮助深表感谢。