Greetings all, Ive been learning rails for the past few months and am getting ready to start my first full blown app. however of course I have run into my first full blown issue. Is there any way to work with multiple databases and db types at the same time in a single app? I have a central user auth db that is used by multiple apps, and my app db is in mysql any hints? thanks, Sam Mayes
As always, check the wonderful API Docs under "Connection to multiple databases in different models" -- http://rails.rubyonrails.com/classes/ActiveRecord/Base.html Here''s the idea. environment.rb sets the DB connection for ActiveRecord::Base. When a model needs to connect, it checks for a connection up its class hierarchy until it finds a connection. Just duplicate this section in your configuration for your model: # default db connection ActiveRecord::Base.configurations File.open("#{RAILS_ROOT}/config/database.yml") { |f| YAML::load(f) } ActiveRecord::Base.establish_connection # central user auth db connection AuthModel.configurations File.open("#{RAILS_ROOT}/config/auth_database.yml") { |f| YAML::load(f) } AuthModel.establish_connection On 7/18/05, Sam Mayes <codeslave-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Greetings all, > > Ive been learning rails for the past few months and am getting ready > to start my first full blown app. however of course I have run into my > first full blown issue. > > Is there any way to work with multiple databases and db types at the > same time in a single app? I have a central user auth db that is used > by multiple apps, and my app db is in mysql any hints? > > thanks, > > Sam Mayes > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- rick http://techno-weenie.net
There''s also something on this topic in the Rails Wiki: http://wiki.rubyonrails.com/rails/show/HowtoUseMultipleDatabases - Rowan On 7/18/05, Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> As always, check the wonderful API Docs under "Connection to multiple > databases in different models" -- > http://rails.rubyonrails.com/classes/ActiveRecord/Base.html > > Here''s the idea. environment.rb sets the DB connection for > ActiveRecord::Base. When a model needs to connect, it checks for a > connection up its class hierarchy until it finds a connection. Just > duplicate this section in your configuration for your model: > > # default db connection > ActiveRecord::Base.configurations > File.open("#{RAILS_ROOT}/config/database.yml") { |f| YAML::load(f) } > ActiveRecord::Base.establish_connection > > # central user auth db connection > AuthModel.configurations > File.open("#{RAILS_ROOT}/config/auth_database.yml") { |f| > YAML::load(f) } > AuthModel.establish_connection > > On 7/18/05, Sam Mayes <codeslave-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Greetings all, > > > > Ive been learning rails for the past few months and am getting ready > > to start my first full blown app. however of course I have run into my > > first full blown issue. > > > > Is there any way to work with multiple databases and db types at the > > same time in a single app? I have a central user auth db that is used > > by multiple apps, and my app db is in mysql any hints?-- Morality is usually taught by the immoral.