More that one db


Here is your answer:

Bahadır Doğan wrote:

Thanks. It would be better if a built-in method for that in Rails, I think. coz 3rd party things may not be stable...

Why? I'd guess that more than 80% of Rails applications don't need to ever do this.

Your argument could be used against *any* plugin for Rails... so is the answer to bundle all plugins into Rails? How is that going to guarantee anymore stability?

Connecting to multiple databases isn't a Rails convention, so it shouldn't be baked into the framework. I've needed this in the past and built a quick extension for ActiveRecord that provided this without any issues and it's been stable for over half a year.

It allows me to do the following in a model and specify when it's talking to which database. (save/create/destroy to one db... find/select from another...)

class Liger < ActiveRecord::Base
   handles_connection_for :other_db # maps to other_db in database.yml
   # ...

class Tiger < ActiveRecord::Base
   delegates_connection_to :liger, :on => [:save, :create, :destroy]

Again, didn't take much work and Rails didn't get in my way.


Bahadır Doğan wrote:

a feature in ActiveRecord to specify to which db and which table is not a too hard thing for the core team, i think.that would solve the plural table names problem, too. if you don't want to specify and want to use default, you can get them blank.

I'm very new in Rails and my approach may be wrong, i'm not sure.

Yes, an addition like that would be a very easy thing for the core team to include. However, this opens up a can of worms. Do you know... just how many "easy" and "small" things people want to include into the core project? If they were all accepted, this would be increase the complexity of the framework to maintain... and would likely slow down their efforts.

Extend ActiveRecord and take this on for yourself. Many people have done it (when necessary)... and we haven't had to bother the core team in the process. :wink: