Note that there are some explanatory texts on larger screens.

plurals
  1. POActiveRecord::ConnectionNotEstablished error (eager loading?)
    primarykey
    data
    text
    <p>I'm developing on OSX and deploying on Linux. My environments are:</p> <p>Development:</p> <pre><code>OSX Lion Ruby 1.9.2p180 ActiveRecord 3.0.9 PostgreSQL 9.0 </code></pre> <p>Test:</p> <pre><code>Ubuntu Server 11.04 Ruby 1.9.2p290 ActiveRecord 3.1.1 PostgreSQL 9.1 </code></pre> <p>The following pieces of code work on OSX but not on Linux:</p> <pre><code>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(....) </code></pre> <p>and:</p> <pre><code>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 } } </code></pre> <p>When I try to run any of these pieces of code in Linux I get the following error:</p> <pre><code>.../connection_pool.rb:409: in `retrieve_connection': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished) </code></pre> <p>I changed the code, and it works on Linux:</p> <pre><code>ei_doc_type = TaxDoc::Model::DocType.find_by_doc_type("EI") doc_versions = TaxDoc::Model::DocVersion.where(:doc_type_id =&gt; ei_doc_type.id, :doc_version =&gt; edoc.version) doc_version = doc_version.first customer.electronic_invoices.create(....) </code></pre> <p>and:</p> <pre><code>ei_doc_type = TaxDoc::Model::DocType.includes(:doc_versions =&gt; :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 } } </code></pre> <p>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.</p> <p>Is there a difference between versions on ActiveRecord or PostgreSQL that could be causing this?</p> <p>These are my models:</p> <pre><code>class DocType &lt; EDocsDatabase has_many :doc_versions, :dependent =&gt; :destroy has_many :mappings, :through =&gt; :doc_versions has_many :service_types end class DocVersion &lt; EDocsDatabase belongs_to :doc_type has_many :mappings, :dependent =&gt; :destroy end class Mapping &lt; EDocsDatabase belongs_to :doc_version end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload