mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
ARel only requires the connection from the AR class. Simply return the AR class rather than jump through hoops and store ivars
This commit is contained in:
parent
1a15fda021
commit
d65e3b481e
3 changed files with 29 additions and 35 deletions
|
@ -747,7 +747,7 @@ module ActiveRecord #:nodoc:
|
|||
undefine_attribute_methods
|
||||
reset_column_cache
|
||||
@column_names = @content_columns = @dynamic_methods_hash = @inheritance_column = nil
|
||||
@arel_engine = @relation = nil
|
||||
@relation = nil
|
||||
end
|
||||
|
||||
def reset_column_cache # :nodoc:
|
||||
|
@ -856,13 +856,7 @@ module ActiveRecord #:nodoc:
|
|||
end
|
||||
|
||||
def arel_engine
|
||||
@arel_engine ||= begin
|
||||
if self == ActiveRecord::Base
|
||||
ActiveRecord::Base
|
||||
else
|
||||
connection_handler.connection_pools[name] ? self : superclass.arel_engine
|
||||
end
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
# Returns a scope for this class without taking into account the default_scope.
|
||||
|
|
|
@ -50,34 +50,34 @@ module ActiveRecord
|
|||
# may be returned on an error.
|
||||
def self.establish_connection(spec = nil)
|
||||
case spec
|
||||
when nil
|
||||
raise AdapterNotSpecified unless defined?(Rails.env)
|
||||
establish_connection(Rails.env)
|
||||
when ConnectionSpecification
|
||||
self.connection_handler.establish_connection(name, spec)
|
||||
when Symbol, String
|
||||
if configuration = configurations[spec.to_s]
|
||||
establish_connection(configuration)
|
||||
else
|
||||
raise AdapterNotSpecified, "#{spec} database is not configured"
|
||||
end
|
||||
when nil
|
||||
raise AdapterNotSpecified unless defined?(Rails.env)
|
||||
establish_connection(Rails.env)
|
||||
when ConnectionSpecification
|
||||
self.connection_handler.establish_connection(name, spec)
|
||||
when Symbol, String
|
||||
if configuration = configurations[spec.to_s]
|
||||
establish_connection(configuration)
|
||||
else
|
||||
spec = spec.symbolize_keys
|
||||
unless spec.key?(:adapter) then raise AdapterNotSpecified, "database configuration does not specify adapter" end
|
||||
raise AdapterNotSpecified, "#{spec} database is not configured"
|
||||
end
|
||||
else
|
||||
spec = spec.symbolize_keys
|
||||
unless spec.key?(:adapter) then raise AdapterNotSpecified, "database configuration does not specify adapter" end
|
||||
|
||||
begin
|
||||
require "active_record/connection_adapters/#{spec[:adapter]}_adapter"
|
||||
rescue LoadError => e
|
||||
raise "Please install the #{spec[:adapter]} adapter: `gem install activerecord-#{spec[:adapter]}-adapter` (#{e})"
|
||||
end
|
||||
begin
|
||||
require "active_record/connection_adapters/#{spec[:adapter]}_adapter"
|
||||
rescue LoadError => e
|
||||
raise "Please install the #{spec[:adapter]} adapter: `gem install activerecord-#{spec[:adapter]}-adapter` (#{e})"
|
||||
end
|
||||
|
||||
adapter_method = "#{spec[:adapter]}_connection"
|
||||
unless respond_to?(adapter_method)
|
||||
raise AdapterNotFound, "database configuration specifies nonexistent #{spec[:adapter]} adapter"
|
||||
end
|
||||
adapter_method = "#{spec[:adapter]}_connection"
|
||||
unless respond_to?(adapter_method)
|
||||
raise AdapterNotFound, "database configuration specifies nonexistent #{spec[:adapter]} adapter"
|
||||
end
|
||||
|
||||
remove_connection
|
||||
establish_connection(ConnectionSpecification.new(spec, adapter_method))
|
||||
remove_connection
|
||||
establish_connection(ConnectionSpecification.new(spec, adapter_method))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -84,8 +84,8 @@ class MultipleDbTest < ActiveRecord::TestCase
|
|||
assert_equal "Ruby Developer", Entrant.find(1).name
|
||||
end
|
||||
|
||||
def test_arel_table_engines
|
||||
assert_not_equal Entrant.arel_engine, Course.arel_engine
|
||||
assert_equal Entrant.arel_engine, Bird.arel_engine
|
||||
def test_connections
|
||||
assert_not_equal Entrant.connection, Course.connection
|
||||
assert_equal Entrant.connection, Bird.connection
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue