aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-02-03 14:04:21 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-02-03 14:04:21 -0800
commit23a3ba426067d3d38259ef4e1d234cbb82c8aea2 (patch)
tree796e2b13201d06e141adee7f69f6d3ae9ddc53ce /activerecord/lib/active_record
parent95d5d9b6c48c08f1fba0c77ecbc97b62b2603824 (diff)
downloadrails-23a3ba426067d3d38259ef4e1d234cbb82c8aea2.tar.gz
rails-23a3ba426067d3d38259ef4e1d234cbb82c8aea2.tar.bz2
rails-23a3ba426067d3d38259ef4e1d234cbb82c8aea2.zip
Revert "ARel only requires the connection from the AR class. Simply return the AR class rather than jump through hoops and store ivars"
This reverts commit d65e3b481e72e8c76818a94353e9ac315c7c0272.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/base.rb10
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb48
2 files changed, 32 insertions, 26 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 4e743ec826..8750e226b9 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -747,7 +747,7 @@ module ActiveRecord #:nodoc:
undefine_attribute_methods
reset_column_cache
@column_names = @content_columns = @dynamic_methods_hash = @inheritance_column = nil
- @relation = nil
+ @arel_engine = @relation = nil
end
def reset_column_cache # :nodoc:
@@ -856,7 +856,13 @@ module ActiveRecord #:nodoc:
end
def arel_engine
- self
+ @arel_engine ||= begin
+ if self == ActiveRecord::Base
+ ActiveRecord::Base
+ else
+ connection_handler.connection_pools[name] ? self : superclass.arel_engine
+ end
+ end
end
# Returns a scope for this class without taking into account the default_scope.
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
index 5a6d13e64b..3716937689 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
@@ -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)
+ 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
else
- 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
+ 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