Forum: Ruby on Rails multiple database connections

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
29ebf90af6107d2eb39b587c7972639c?d=identicon&s=25 Mukund (Guest)
on 2008-12-05 06:36
(Received via mailing list)
For multiple database connections,  is it better to have a mixin
included into the model that does a establish connection on included
event or is it better to have an abstract class that establishes the
connnection and inherit from the abstract class?   In particular, how
do Rails handle database connections?   It is supposed to use a
connection pool, does the pooling break if you use a mixin?

Mixin:

 module CustomConnect

  def self.included(base)
    config = ActiveRecord::Base.configurations["custom_"+RAILS_ENV]
    base.establish_connection(config)
  end

end

and then you do a

class abc < ActiveRecord::Base

include CustomConnect

end

Inheritance:

class CustomConnect < ActiveRecord::Base

  self.abstract_class = true
  config = ActiveRecord::Base.configurations["custom_"+RAILS_ENV]
  establish_connection(config)

end

class abc < CustomConnect

end

When you have a significant number of models, how are database
connections handled and which approach is better?
29ebf90af6107d2eb39b587c7972639c?d=identicon&s=25 Mukund (Guest)
on 2008-12-07 04:51
(Received via mailing list)
Does anyone have an input on connection pooling and which approach is
better?
This topic is locked and can not be replied to.