More that one db

Bahadır Doğan wrote:


Sometimes I need to work with more than one databases. When I look at
database.yml file, I see that only one database is specified. Is it
possible to work with more than one databases?

Yes you can. In your database.yml file setup a new entry. E.g.:

   adapter: mysql
   database: legacy

In your model use "establish_connection :<database_entry>". E.g.:

class Departments < ActiveRecord::Base
   establish_connection :legacy

Just be aware that AR (like most LAMP stuff, afaik) doesn't support
distributed transactions. When you start modifying multiple databases
at once, data integrity is no longer guaranteed.


what does it mean "modifying multiple databases at once" ?

Let me rephrase:
You can't make a transaction span multiple databases using AR (or Ruby
in general, as far as i know).

If that's a requirement, your best bet is probably handing the work
over to a Java web service or something along those lines.
Then again, this may not be neccessary for your application.