class MultiAR::Model

Base model for different model groups to include.

This is not supposed to be included by models itself, instead you should have common main parent model that extends this model, and the actual model should extend that model.

Public Class Methods

database_config=(config) click to toggle source

Can be used to set custom database config.

# File lib/multi_ar/model.rb, line 19
def self.database_config= config
  @db_config = config
end

Protected Class Methods

establish_connection(connection_name) click to toggle source
Calls superclass method
# File lib/multi_ar/model.rb, line 25
def self.establish_connection connection_name
  raise "MultiAR app must be initialized first" if MultiAR.app.nil?
  Database.initialize db_config: MultiAR.app.db_config
  real_connection_name = Database.connection_name connection_name
  raise "Connection #{real_connection_name} is not present in the db config file #{MultiAR.app.db_config}" if not Database.database_config[real_connection_name]

  super Database.database_config[real_connection_name]
end