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_specification.rb, line 250 def self.retrieve_connection #:nodoc: # Name is nil if establish_connection hasn't been called for # some class along the inheritance chain up to AR::Base yet. if name = active_connection_name if conn = active_connections[name] # Verify the connection. conn.verify!(@@verification_timeout) elsif spec = @@defined_connections[name] # Activate this connection specification. klass = name.constantize klass.connection = spec conn = active_connections[name] end end conn or raise ConnectionNotEstablished end