ConnectionHandler is a collection of ConnectionPool objects. It is used for keeping separate connection pools for Active Record models that connect to different databases.

For example, suppose that you have 5 models, with the following hierarchy:

class Author < ActiveRecord::Base

class BankAccount < ActiveRecord::Base

class Book < ActiveRecord::Base
  establish_connection "library_db"

class ScaryBook < Book

class GoodBook < Book

And a database.yml that looked like this:

  database: my_application
  host: localhost

  database: library
  host: some.library.org

Your primary database in the development environment is “my_application” but the Book model connects to a separate database called “library_db” (this can even be a database on a different machine).

Book, ScaryBook and GoodBook will all use the same connection pool to “library_db” while Author, BankAccount, and any other models you create will use the default connection pool to “my_application”.

The various connection pools are managed by a single instance of ConnectionHandler accessible via ActiveRecord::Base.connection_handler. All Active Record models use this handler to determine the connection pool that they should use.

Show files where this class is defined (1 file)
Register or log in to add new notes.