Good morning, I''m currently running my Rails app out of PostgreSQL database but I''ve gotten to a point where I need to query another Oracle database to retrieve a single record. I''ve seen approaches like this: http://wiki.rubyonrails.org/rails/pages/HowtoUseMultipleDatabases But is this the right method for me? When a user uses my application it determines who they are via their Windows Login. Using that login I have the capability to query an Oracle database and retrieve all the information on that user. So when the user logs into my application I would like to make the call to that Oracle database, pull down their information and continue with the application never having to access the Oracle database again. Are there any other known methods out there that work very well? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 10/16/07, Matthew Williams <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Good morning, > > I''m currently running my Rails app out of PostgreSQL database but I''ve > gotten to a point where I need to query another Oracle database to > retrieve a single record. > > I''ve seen approaches like this: > http://wiki.rubyonrails.org/rails/pages/HowtoUseMultipleDatabases > > But is this the right method for me? > > When a user uses my application it determines who they are via their > Windows Login. Using that login I have the capability to query an > Oracle database and retrieve all the information on that user. So when > the user logs into my application I would like to make the call to that > Oracle database, pull down their information and continue with the > application never having to access the Oracle database again.Is there one Oracle DB or are there several and which one needs to be determined based on the user or some other criteria? The article you link to talks about the latter. It it''s just one DB and you have one or more tables to be ''statically'' connected to that DB , then see http://rails.rubyonrails.com/classes/ActiveRecord/Base.html and look for the section "Connection to multiple databases in different models" You probably want to call establish_connection with the right connection parameters for the table(s) to be connected to the oracle DB in your config/environment.rb file in a config.after_initialize block. If you''ve got several tables you can make an abstract AR class for those models to subclass, and establish the connection for the abstract class which will take care of the subclass. I''m working on a project right now which does something similar. One thing I''ve found is that most of the testing infrastructure of rails doesn''t really handle tables with their own connections very well, what I''ve done is to put analogs of those tables directly in the main test environment database. I wrote the migrations for the ''external'' tables so that they only actually create the tables if ENV[''RAILS_ENV''] is ''test'' -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Williams
2007-Oct-16 17:20 UTC
Re: Best solution for accessing multiple databases?
Philip Hallstrom wrote:>> Windows Login. Using that login I have the capability to query an >> Oracle database and retrieve all the information on that user. So when >> the user logs into my application I would like to make the call to that >> Oracle database, pull down their information and continue with the >> application never having to access the Oracle database again. > > Why wouldn''t you setup the oracle database in database.yml then create a > model like ''AllUserInfo'' or something that makes more sense and define > it > like this: > > class AllUserInfo < ActiveRecord::Base > establish_connection ''oracle_db_defined_in_yml_file'' > set_table_name ''whatever my table name is'' > end > > and then just do... > > all_info_about_a_user = AllUserInfo.find(:first, :conditions....) > > ?I was unaware of this capability but it seems like the best bet. That''s all I really need to do, it''s a single Oracle database with just one lookup table that I need to access. Thanks for the tip, I''ll give it a shot. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Oct-16 18:25 UTC
Re: Best solution for accessing multiple databases?
> I''m currently running my Rails app out of PostgreSQL database but I''ve > gotten to a point where I need to query another Oracle database to > retrieve a single record. > > I''ve seen approaches like this: > http://wiki.rubyonrails.org/rails/pages/HowtoUseMultipleDatabases > > But is this the right method for me? > > When a user uses my application it determines who they are via their > Windows Login. Using that login I have the capability to query an > Oracle database and retrieve all the information on that user. So when > the user logs into my application I would like to make the call to that > Oracle database, pull down their information and continue with the > application never having to access the Oracle database again.Why wouldn''t you setup the oracle database in database.yml then create a model like ''AllUserInfo'' or something that makes more sense and define it like this: class AllUserInfo < ActiveRecord::Base establish_connection ''oracle_db_defined_in_yml_file'' set_table_name ''whatever my table name is'' end and then just do... all_info_about_a_user = AllUserInfo.find(:first, :conditions....) ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---