Locate the connection of the nearest super class. This can be an active or
defined connection: if it is the latter, it will be opened and set as the
active connection for the class it was defined for (not necessarily the
current class).
# File activerecord/lib/active_record/connection_adapters/abstract/connection_handler.rb, line 231
def retrieve_connection(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard) # :nodoc:
pool = retrieve_connection_pool(connection_name, role: role, shard: shard)
unless pool
if shard != ActiveRecord::Base.default_shard
message = "No connection pool for '#{connection_name}' found for the '#{shard}' shard."
elsif role != ActiveRecord::Base.default_role
message = "No connection pool for '#{connection_name}' found for the '#{role}' role."
else
message = "No connection pool for '#{connection_name}' found."
end
raise ConnectionNotEstablished, message
end
pool.connection
end