次のコードで 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'
どんな助けでも大歓迎です。