5MileRadius wrote:
> Sure, try this on a model object (say called Planet):
>
> class Planet < ActiveRecord::Base
> establish_connection(:adapter => "mysql", :host => "mydbserver.com",
> :database => "myDb" .... )
>
> end
>
> where '...' are the other paramters to use in the connection. This
> will result in the Planet model using the db connection defined above.
But how can I differentiate between a reader and a writer database? It
seems to be rails limitation here..
I like PostgreSQL and would like to use it, but I have to do my due
diligence in looking for similar solutions on top of our current RDBMS
(MySQL) and, potentially, any commercial databases.
The pgpool solution (or, rather, pgpool-II) looks great in that both
read/write partitioning and vertical (row) partitioning is completely
transparent to the application layer. Does anyone know of anything like
that, commercial or otherwise, exist for MySQL or the various commercial
RDBMSs?
There are no issues at all with establishing as many connections as you
wish. This issue lies more with linking them to a model more then
making the connection.
What is below is an example - stolen blatantly from earlier in the thread…
To do what you want below - I might be tempted to have a base model for
users and then create at least one subclass that had look like
class DBxUser < User
establish_connection…(to DBx)
end
Then from your controller create both a User and a DBxUser and then
make you concatenated array by calling into both of them. I’m assuming
that at least one of the two database connections is the standard
connection you use for the rest of your connection (i.e. the one listed
under config/database.yml).