Paweł K
2008-Dec-06 13:17 UTC
Is there any way to use separated databases for models in one RoR app?
Like in topic - is there any simple and elegant way to use separated databases for specified models in one RoR app? Here is the example: I''d like to have separated DB for user data (model "Account" with credentials, account info etc. for security purpose), different one for Payment model (date, amount etc.) and third one for (i.e.) store data. Is there any way to do this with maintaining ActiveRecord relations between models? (like account.has_many => payments :D)??? Thanks in advance guys :) Paweł Komarnicki, http://komarnicki.webd.pl --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Dec-06 14:31 UTC
Re: Is there any way to use separated databases for models in one RoR app?
On Dec 6, 1:17 pm, Paweł K <komr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Like in topic - is there any simple and elegant way to use separated > databases for specified models in one RoR app? > > Here is the example: > I''d like to have separated DB for user data (model "Account" with > credentials, account info etc. for security purpose), different one > for Payment model (date, amount etc.) and third one for (i.e.) store > data.see the section titled "Connection to multiple databases in different models" at http://rails.rubyonrails.com/classes/ActiveRecord/Base.html> > Is there any way to do this with maintaining ActiveRecord relations > between models? (like account.has_many => payments :D)??? >Probably (unless you try an do things like joins between two databases not served by the same database server or stuff like that) Fred> Thanks in advance guys :) > Paweł Komarnicki,http://komarnicki.webd.pl--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Paweł K
2008-Dec-06 21:44 UTC
Re: Is there any way to use separated databases for models in one RoR app?
Thanks Fred, indeed there is some info about that, but... it''s a bit unclear to me how to use it... Do I specify establisch_connection command in model file? Or in configuration script? Thanks for help :) Paweł Komarnicki On 6 Gru, 15:31, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 6, 1:17 pm, Paweł K <komr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Like in topic - is there any simple and elegant way to use separated > > databases for specified models in one RoR app? > > > Here is the example: > > I''d like to have separated DB for user data (model "Account" with > > credentials, account info etc. for security purpose), different one > > for Payment model (date, amount etc.) and third one for (i.e.) store > > data. > > see the section titled "Connection to multiple databases in different > models" athttp://rails.rubyonrails.com/classes/ActiveRecord/Base.html > > > Is there any way to do this with maintaining ActiveRecord relations > > between models? (like account.has_many => payments :D)??? > > Probably (unless you try an do things like joins between two databases > not served by the same database server or stuff like that) > > Fred > > > Thanks in advance guys :) > > Paweł Komarnicki,http://komarnicki.webd.pl--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Maurício Linhares
2008-Dec-06 22:21 UTC
Re: Is there any way to use separated databases for models in one RoR app?
You specify it at your model, eg: class Client < ActiveRecord::Base establish_connection *put_your_config_here* end Then all queries against that model will use it's connection. - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) 2008/12/6 Paweł K <komrath@gmail.com>:> > Thanks Fred, > > indeed there is some info about that, but... it's a bit unclear to me > how to use it... Do I specify establisch_connection command in model > file? Or in configuration script? > > Thanks for help :) > Paweł Komarnicki > > On 6 Gru, 15:31, Frederick Cheung <frederick.che...@gmail.com> wrote: >> On Dec 6, 1:17 pm, Paweł K <komr...@gmail.com> wrote:> Like in topic - is there any simple and elegant way to use separated >> > databases for specified models in one RoR app? >> >> > Here is the example: >> > I'd like to have separated DB for user data (model "Account" with >> > credentials, account info etc. for security purpose), different one >> > for Payment model (date, amount etc.) and third one for (i.e.) store >> > data. >> >> see the section titled "Connection to multiple databases in different >> models" athttp://rails.rubyonrails.com/classes/ActiveRecord/Base.html >> >> > Is there any way to do this with maintaining ActiveRecord relations >> > between models? (like account.has_many => payments :D)??? >> >> Probably (unless you try an do things like joins between two databases >> not served by the same database server or stuff like that) >> >> Fred >> >> > Thanks in advance guys :) >> > Paweł Komarnicki,http://komarnicki.webd.pl > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Dec-07 09:57 UTC
Re: Is there any way to use separated databases for models in one RoR app?
On Dec 6, 10:21 pm, "Maurício Linhares" <mauricio.linha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You specify it at your model, eg: > > class Client < ActiveRecord::Base > establish_connection *put_your_config_here* > end > > Then all queries against that model will use it''s connection.Yup. One tip if you''ve got several models using the same configuratrion is that you can do class Foo < ActiveRecord::Base establish_connection :other_database end and that will take the parameters from database.yml for the configuration named other_database. Fred> > - > Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) |http://blog.codevader.com/(en) > > 2008/12/6 Paweł K <komr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > Thanks Fred, > > > indeed there is some info about that, but... it''s a bit unclear to me > > how to use it... Do I specify establisch_connection command in model > > file? Or in configuration script? > > > Thanks for help :) > > Paweł Komarnicki > > > On 6 Gru, 15:31, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> On Dec 6, 1:17 pm, Paweł K <komr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Like in topic - is there any simple and elegant way to use separated > >> > databases for specified models in one RoR app? > > >> > Here is the example: > >> > I''d like to have separated DB for user data (model "Account" with > >> > credentials, account info etc. for security purpose), different one > >> > for Payment model (date, amount etc.) and third one for (i.e.) store > >> > data. > > >> see the section titled "Connection to multiple databases in different > >> models" athttp://rails.rubyonrails.com/classes/ActiveRecord/Base.html > > >> > Is there any way to do this with maintaining ActiveRecord relations > >> > between models? (like account.has_many => payments :D)??? > > >> Probably (unless you try an do things like joins between two databases > >> not served by the same database server or stuff like that) > > >> Fred > > >> > Thanks in advance guys :) > >> > Paweł Komarnicki,http://komarnicki.webd.pl--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---