Hello!
I’ve looked through the mailing list archives, but havn’t found a viable
answer for this question. I would like to have my rails app handle a
couple tables in a legacy database. Looking at the wiki, comments in
the
rails code, and searching for past comments on this list, I’ve tried two
different methods that are both broken. At least for PostgreSQL, I
havn’t
testing this bug with any other databases.
First method is establishing the connection in environment.rb like such:
MyModel.establish_connection :my_db
This only works the first time if the page loaded uses MyModel. All
subsequent calls defaults to the connection for ActiveRecord::Base. I
can
see the entry in active_connections, but it doesn’t seem to be used.
Second option is putting the extablish_connection directly in the
my_model.rb file.
class MyModel < ActiveRecord::Base
establish_connection :my_db
end
This works… until you start having your db complain about too many
connections. It will open a new database connection each time you
access
the model, and it leaves all previous connections open. Taking a look
at
active_connections will show multiple entries for MyModel.
Does anyone have a solution that will work, and won’t make multiple
connections that will never be used again?
Thanks for any help,
Ken…