This project is archived and is in readonly mode.
ActiveRecord.establish_connection uses class variable instead of accessor method
Reported by ronin-37489 (at lighthouseapp) | November 14th, 2008 @ 06:30 AM | in 2.x
Is there a reason ActiveRecord.establish_connection
uses @@connection_handler.establish_connection
instead
of connection_handler.establish_connection?
I'm trying
to make a subclass of ActiveRecord::Base
that has it's
own ConnectionHandler
instance and I would want to
leave ActiveRecord::Base
's connection handler exactly
the same. Here is what I'm trying to do:
class AnotherActiveRecord < ActiveRecord::Base
@@another_connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
def connection_handler
@@another_connection_handler
end
end
Would it be possible for establish_connection
to
use connection_handler
accessor method so that this
overloading can be done easier? Or is there a better way to do
this?
Thanks!
Comments and changes to this ticket
-
Pratik March 10th, 2009 @ 12:29 PM
- Assigned user set to Pratik
- State changed from new to invalid
You should just call establish_connection() from the model instead of overriding connection_handler.
class Model < ActiveRecord::Base establish_connection ... end
-
ronin-37489 (at lighthouseapp) March 10th, 2009 @ 05:05 PM
I would normally do just that. However, for this case, I need to connect to many databases with the same schema. Therefore, if the connection handler has a cache of connections based on the model name, then this would work. Ideally, the connection handler should cache on the hostname + database name + table. Or, in my case, overriding the connection handler with it's own cache.
-
ronin-37489 (at lighthouseapp) March 10th, 2009 @ 05:06 PM
correction: ...then this would not work..
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>