On Dec 28, 2007, at 7:50 AM, Ersin Er wrote:
I know that it’s possible to use multiple databases with Rails.
However most of the examples I have seen were for high availability. I
would like to learn if anyone has any experience with a shared
database among many rails applications. Such a case may make sense for
shared user information. Any ideas?
I have not done anything like this yet (am planning on it for a
future project), but I did just come across this in the api docs:
Connections are usually created through
ActiveRecord::Base.establish_connection and retrieved by
ActiveRecord::Base.connection. All classes inheriting from
ActiveRecord::Base will use this connection. But you can also set a
class-specific connection. For example, if Course is an
ActiveRecord::Base, but resides in a different database, you can just
say Course.establish_connection and Course and all its subclasses
will use this connection instead.
This feature is implemented by keeping a connection pool in
ActiveRecord::Base that is a Hash indexed by the class. If a
connection is requested, the retrieve_connection method will go up
the class-hierarchy until a connection is found in the connection pool.