Is there any way to use separated databases for models in one RoR app?

Like in topic - is there any simple and elegant way to use separated
databases for specified models in one RoR app?

Here is the example:
I’d like to have separated DB for user data (model “Account” with
credentials, account info etc. for security purpose), different one
for Payment model (date, amount etc.) and third one for (i.e.) store
data.

Is there any way to do this with maintaining ActiveRecord relations
between models? (like account.has_many => payments :D)???

Thanks in advance guys :slight_smile:
Pawe³ Komarnicki, http://komarnicki.webd.pl

On Dec 6, 1:17 pm, Pawe³ K [email protected] wrote:

Like in topic - is there any simple and elegant way to use separated
databases for specified models in one RoR app?

Here is the example:
I’d like to have separated DB for user data (model “Account” with
credentials, account info etc. for security purpose), different one
for Payment model (date, amount etc.) and third one for (i.e.) store
data.
see the section titled “Connection to multiple databases in different
models” at Peak Obsession

Is there any way to do this with maintaining ActiveRecord relations
between models? (like account.has_many => payments :D)???

Probably (unless you try an do things like joins between two databases
not served by the same database server or stuff like that)

Fred

Thanks Fred,

indeed there is some info about that, but… it’s a bit unclear to me
how to use it… Do I specify establisch_connection command in model
file? Or in configuration script?

Thanks for help :slight_smile:
Pawe³ Komarnicki

On Dec 6, 10:21 pm, “Maurício Linhares” [email protected]
wrote:

You specify it at your model, eg:

class Client < ActiveRecord::Base
establish_connection put_your_config_here
end

Then all queries against that model will use it’s connection.

Yup. One tip if you’ve got several models using the same
configuratrion is that you can do

class Foo < ActiveRecord::Base
establish_connection :other_database
end

and that will take the parameters from database.yml for the
configuration named other_database.

Fred

You specify it at your model, eg:

class Client < ActiveRecord::Base
establish_connection put_your_config_here
end

Then all queries against that model will use it’s connection.

Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)

2008/12/6 Pawe³ K [email protected]: