method

connects_to

Importance_1
v6.0.0 - Show latest stable - 0 notes - Class: ConnectionHandling
connects_to(database: {}) public

Connects a model to the databases specified. The database keyword takes a hash consisting of a role and a database_key.

This will create a connection handler for switching between connections, look up the config hash using the database_key and finally establishes a connection to that config.

class AnimalsModel < ApplicationRecord
  self.abstract_class = true

  connects_to database: { writing: :primary, reading: :primary_replica }
end

Returns an array of established connections.

Show source
Register or log in to add new notes.