[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Multiple database connections

James Lopes

5/1/2009 3:12:00 PM


A quick question:

Say my project needs to connect to a second database, Users stored in
one db and data in another, How would I configure my projects
database.yml?

Thanks for the help.
--
Posted via http://www.ruby-....

4 Answers

Loga Ganesan

5/2/2009 4:25:00 AM

0

James Lopes wrote:
>
> A quick question:
>
> Say my project needs to connect to a second database, Users stored in
> one db and data in another, How would I configure my projects
> database.yml?
>
> Thanks for the help.

Hi ,
You can put one more database entry in either the development,
test or production.
--
Posted via http://www.ruby-....

Mark Thomas

5/3/2009 1:07:00 AM

0

On May 2, 12:24 am, Loga Ganesan <loganathan_...@yahoo.co.in> wrote:
> James Lopes wrote:
>
> > A quick question:
>
> > Say my project needs to connect to a second database, Users stored in
> > one db and data in another, How would I configure my projects
> > database.yml?
>
> > Thanks for the help.
>
> Hi ,
>       You can put one more database entry in either the development,
> test or production.

First, this is a Rails question, so it is best asked on the Rails
list.
Secondly, the above advice is incorrect, which I guess proves the
first point. Each entry in database.yml is a connection. You can
create additional connections. See
http://pullmonkey.com/2008/4/21/ruby-on-rails-multiple-database-c...

-- Mark.

list. rb

5/3/2009 3:43:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

I used a multi-magic (think that was the spelling) gem a while back, worked
well as a standalone & w/ rails.
Good luck

On Sat, May 2, 2009 at 9:10 PM, Mark Thomas <mark@thomaszone.com> wrote:

> On May 2, 12:24 am, Loga Ganesan <loganathan_...@yahoo.co.in> wrote:
> > James Lopes wrote:
> >
> > > A quick question:
> >
> > > Say my project needs to connect to a second database, Users stored in
> > > one db and data in another, How would I configure my projects
> > > database.yml?
> >
> > > Thanks for the help.
> >
> > Hi ,
> > You can put one more database entry in either the development,
> > test or production.
>
> First, this is a Rails question, so it is best asked on the Rails
> list.
> Secondly, the above advice is incorrect, which I guess proves the
> first point. Each entry in database.yml is a connection. You can
> create additional connections. See
> http://pullmonkey.com/2008/4/21/ruby-on-rails-multiple-database-c...
>
> -- Mark.
>
>

Rick DeNatale

5/3/2009 7:44:00 PM

0

On Sat, May 2, 2009 at 9:10 PM, Mark Thomas <mark@thomaszone.com> wrote:
> On May 2, 12:24=A0am, Loga Ganesan <loganathan_...@yahoo.co.in> wrote:
>> James Lopes wrote:
>>
>> > A quick question:
>>
>> > Say my project needs to connect to a second database, Users stored in
>> > one db and data in another, How would I configure my projects
>> > database.yml?
>>
>> > Thanks for the help.
>>
>> Hi ,
>> =A0 =A0 =A0 You can put one more database entry in either the developmen=
t,
>> test or production.
>
> First, this is a Rails question, so it is best asked on the Rails
> list.
> Secondly, the above advice is incorrect, which I guess proves the
> first point. Each entry in database.yml is a connection. You can
> create additional connections. See
> http://pullmonkey.com/2008/4/21/ruby-on-rails-multiple-database-...
ns

One thing which the link doesn't seem to mention is that if you have
more than one model which needs to be in second database, you can make
an abstract superclass.

e.g.

class SecondDatabaseBase < ActiveRecord::Base
self.abstract_class =3D true
establish_connection ("connection_key")
end

where "connection_key" would be substituted for a key in database.yml,
possibly computed using RAILS_ENV.

Then just make models which are in the second database subclasses of
SecondDatabaseBase instead of ActiveRecord::Base.

Setting the class attribute abstract_class to true tells AR that the
class doesn't have any instances, but is just providing configuration
info, methods etc. to any subclasses.


--=20
Rick DeNatale

Blog: http://talklikeaduck.denh...
Twitter: http://twitter.com/Ri...
WWR: http://www.workingwithrails.com/person/9021-ric...
LinkedIn: http://www.linkedin.com/in/ri...