aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/core.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-12-28 18:07:08 +0000
committerJon Leighton <j@jonathanleighton.com>2011-12-28 18:27:41 +0000
commitdae7b6545372cba40e08554b9a7b2f391eaa5c6e (patch)
tree6035c63c71dc0243560412b08110bd7e496f8552 /activerecord/lib/active_record/core.rb
parent93c1f11c0a5097a5431819a1551a02a869a16a38 (diff)
downloadrails-dae7b6545372cba40e08554b9a7b2f391eaa5c6e.tar.gz
rails-dae7b6545372cba40e08554b9a7b2f391eaa5c6e.tar.bz2
rails-dae7b6545372cba40e08554b9a7b2f391eaa5c6e.zip
Support establishing connection on ActiveRecord::Model.
This is the 'top level' connection, inherited by any models that include ActiveRecord::Model or inherit from ActiveRecord::Base.
Diffstat (limited to 'activerecord/lib/active_record/core.rb')
-rw-r--r--activerecord/lib/active_record/core.rb15
1 files changed, 8 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index c29a0032bc..2379c09ea0 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -119,13 +119,7 @@ module ActiveRecord
end
def arel_engine
- @arel_engine ||= begin
- if self == ActiveRecord::Base
- ActiveRecord::Base
- else
- connection_handler.connection_pools[name] ? self : active_record_super.arel_engine
- end
- end
+ @arel_engine ||= connection_handler.connection_pools[name] ? self : active_record_super.arel_engine
end
private
@@ -304,6 +298,13 @@ module ActiveRecord
@readonly = true
end
+ # Returns the connection currently associated with the class. This can
+ # also be used to "borrow" the connection to do database work that isn't
+ # easily done without going straight to SQL.
+ def connection
+ self.class.connection
+ end
+
# Returns the contents of the record as a nicely formatted string.
def inspect
inspection = if @attributes