Hello, Sometimes I need to work with more than one databases. When I look at database.yml file, I see that only one database is specified. Is it possible to work with more than one databases? -- 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 -~----------~----~----~----~------~----~------~--~---
Hello, Here is your answer: http://drnicwilliams.com/2007/04/12/magic-multi- connections-a-facility-in-rails-to-talk-to-more-than-one-database-at- a-time/> > Hello, > > Sometimes I need to work with more than one databases. When I look at > database.yml file, I see that only one database is specified. Is it > possible to work with more than one databases? > -- > 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 -~----------~----~----~----~------~----~------~--~---
Thanks. It would be better if a built-in method for that in Rails, I think. coz 3rd party things may not be stable... Aurélien Bottazini wrote:> Hello, > > Here is your answer: http://drnicwilliams.com/2007/04/12/magic-multi- > connections-a-facility-in-rails-to-talk-to-more-than-one-database-at- > a-time/-- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 # ... end class Tiger < ActiveRecord::Base delegates_connection_to :liger, :on => [:save, :create, :destroy] #... end Again, didn''t take much work and Rails didn''t get in my way. Robby -- Robby Russell http://www.robbyonrails.com/ http://www.planetargon.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. Robby Russell wrote:> 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 > # ... > end > > class Tiger < ActiveRecord::Base > delegates_connection_to :liger, :on => [:save, :create, :destroy] > #... > end > > Again, didn''t take much work and Rails didn''t get in my way. > > Robby > > > -- > Robby Russell > http://www.robbyonrails.com/ > http://www.planetargon.com/-- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. ;-) Robby -- Robby Russell http://www.robbyonrails.com/ http://www.planetargon.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bahadır Doğan wrote:> Hello, > > Sometimes I need to work with more than one databases. When I look at > database.yml file, I see that only one database is specified. Is it > possible to work with more than one databases?Yes you can. In your database.yml file setup a new entry. E.g.: legacy: adapter: mysql database: legacy ... In your model use "establish_connection :<database_entry>". E.g.: class Departments < ActiveRecord::Base establish_connection :legacy ... -- Michael Wang --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yes, that''s exactly what i need. Thanks, Michael. -- 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 7/30/07, Bahadır Doğan <rails-mailing-list@andreas-s.net> wrote:> > Yes, that's exactly what i need. >Just be aware that AR (like most LAMP stuff, afaik) doesn't support distributed transactions. When you start modifying multiple databases at once, data integrity is no longer guaranteed. Isak --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
what does it mean "modifying multiple databases at once" ? Isak Hansen wrote:> On 7/30/07, Bahadır Doğan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> Yes, that''s exactly what i need. >> > > Just be aware that AR (like most LAMP stuff, afaik) doesn''t support > distributed transactions. When you start modifying multiple databases > at once, data integrity is no longer guaranteed. > > Isak-- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 7/30/07, Bahadır Doğan <rails-mailing-list@andreas-s.net> wrote:> > what does it mean "modifying multiple databases at once" ? >Let me rephrase: You can't make a transaction span multiple databases using AR (or Ruby in general, as far as i know). If that's a requirement, your best bet is probably handing the work over to a Java web service or something along those lines. Then again, this may not be neccessary for your application. Isak> > > Isak Hansen wrote: > > On 7/30/07, Bahadır Doğan <rails-mailing-list@andreas-s.net> wrote: > >> > >> Yes, that's exactly what i need. > >> > > > > Just be aware that AR (like most LAMP stuff, afaik) doesn't support > > distributed transactions. When you start modifying multiple databases > > at once, data integrity is no longer guaranteed. > > > > Isak > > -- > 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---