In my rails app i need to use more than one db in app. But how can i told rails, that this table must be from this db, another – from another. I’m using mysql.
now config looks like this:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: Mycorp_development
pool: 5
username: root
password: root
socket: /var/run/mysqld/mysqld.sock
and one of model (i know that is not in rails-way, but db is non-my)
class Article < ActiveRecord::Base
attr_accessible :ART_ID, :ART_ARTICLE_NR, :ART_SUP_ID, :ART_DES_ID, :ART_COMPLETE_DES_ID, :ART_CTM, :ART_PACK_SELFSERVICE, :ART_MATERIAL_MARK, :ART_REPLACEMENT, :ART_ACCESSORY, :ART_BATCH_SIZE1, :ART_BATCH_SIZE2, :QUANTITYM, :PRICEM
set_table_name "ARTICLES"
set_primary_key :ART_ID
end
ActiveRecord hasn’t been made to communicate to two different databases.
Sure https://github.com/cherring/connection_ninja seems to provide a workaround, I haven’t tested it but I’d very careful using this.
You’re putting yourself in a case that wasn’t planned by the developers, meaning you could hit some walls and having to dig into AR internals to understand what’s going on.
Given you really need to handle two databases, I strongly suggest considering these two alternatives that both support multiple databases out of the box :
They work nicely with Rails 3.