1

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
2

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

i know it), but for developing must to connect to other db, becouse on my drive now i haven't so much free space: so i need to get some ables from another project
Ah if you don't mix the records, you should not have many issues then by using the workaround. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.