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
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
testing this bug with any other databases.
First method is establishing the connection in environment.rb like such:
This only works the first time if the page loaded uses MyModel. All
subsequent calls defaults to the connection for ActiveRecord::Base. I
see the entry in active_connections, but it doesn’t seem to be used.
Second option is putting the extablish_connection directly in the
class MyModel < ActiveRecord::Base
This works… until you start having your db complain about too many
connections. It will open a new database connection each time you
the model, and it leaves all previous connections open. Taking a look
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,