I am developing OSX and deploying to Linux. My environment:
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 code snippets work on OSX, but not 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 code snippets on 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 that impatient loading for first-order associations does not work in the test environment and in the first example. Even if I use "includes", it does not work.
Is there a difference between ActiveRecord or PostgreSQL versions that might 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