gpt4 book ai didi

ruby - ActiveRecord::ConnectionNotEstablished 错误(急切加载?)

转载 作者:数据小太阳 更新时间:2023-10-29 07:20:01 25 4
gpt4 key购买 nike

我在 OSX 上开发并在 Linux 上部署。我的环境是:

发展:

OSX Lion
Ruby 1.9.2p180
ActiveRecord 3.0.9
PostgreSQL 9.0

测试:

Ubuntu Server 11.04
Ruby 1.9.2p290
ActiveRecord 3.1.1
PostgreSQL 9.1

以下代码片段适用于 OSX 但不适用于 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(....)

和:

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
}
}

当我尝试在 Linux 中运行这些代码片段时,出现以下错误:

.../connection_pool.rb:409: in `retrieve_connection': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)

我更改了代码,它可以在 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(....)

和:

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
}
}

一阶关联的预加载似乎在测试环境和第一个示例中不起作用。即使我使用“包含”它也不起作用。

ActiveRecord 或 PostgreSQL 上的版本之间是否存在可能导致此问题的差异?

这些是我的模型:

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

最佳答案

您在什么情况下使用此代码?

原因是——如果您在响应循环中(比如在服务器中)运行代码,目前 ActiveRecord 需要一些连接池管理。 Rails 使用一个中间件来解决这个问题,该中间件在您的主要应用程序响应器之外为您管理 AR 连接。但是,如果您没有这种包装器,您可能会有其他应用程序例程“踩踏”您的连接池,尤其是在使用线程服务器时。

关于ruby - ActiveRecord::ConnectionNotEstablished 错误(急切加载?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7755747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com