I'm developing on OSX and deploying on Linux. My environments are:
Development:
OSX Lion
Ruby 1.9.2p180
ActiveRecord 3.0.9
PostgreSQL 9.0
Test:
Ubuntu Server 11.04
Ruby 1.9.2p290
ActiveRecord 3.1.1
PostgreSQL 9.1
The following pieces of code work on OSX but not on Linux:
ei_doc_type = TaxDoc::Model::DocType.find_by_doc_type("EI")
doc_version = ei_doc_type.doc_versions.find_by_doc_version(edoc.version)
customer.electronic_invoices.create(....)
and:
ei_doc_type = TaxDoc::Model::DocType.find_by_doc_type("EI")
ei_doc_type.doc_versions.each { |doc_version|
@mappings[doc_version.doc_version] = Hash.new
doc_version.mappings.each { |mapping|
@mappings[doc_version.doc_version][mapping.column_name] = mapping.xml_element
}
}
When I try to run any of these pieces of code in Linux I get the following error:
.../connection_pool.rb:409: in `retrieve_connection': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)
I changed the code, and it works on Linux:
ei_doc_type = TaxDoc::Model::DocType.find_by_doc_type("EI")
doc_versions = TaxDoc::Model::DocVersion.where(:doc_type_id => ei_doc_type.id, :doc_version => edoc.version)
doc_version = doc_version.first
customer.electronic_invoices.create(....)
and:
ei_doc_type = TaxDoc::Model::DocType.includes(:doc_versions => :mappings).find_by_doc_type("EI")
ei_doc_type.doc_versions.each { |doc_version|
@mappings[doc_version.doc_version] = Hash.new
doc_version.mappings.each { |mapping|
@mappings[doc_version.doc_version][mapping.column_name] = mapping.xml_element
}
}
It seems like eager loading for first order associations is not working on the test environment, and in the first example. Even if I use "includes" it does not work.
Is there a difference between versions on ActiveRecord or PostgreSQL that could be causing this?
These are my models:
class DocType < EDocsDatabase
has_many :doc_versions, :dependent => :destroy
has_many :mappings, :through => :doc_versions
has_many :service_types
end
class DocVersion < EDocsDatabase
belongs_to :doc_type
has_many :mappings, :dependent => :destroy
end
class Mapping < EDocsDatabase
belongs_to :doc_version
end