aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/connection_handling.rb22
1 files changed, 13 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb
index e3b59b8a22..777cb8a402 100644
--- a/activerecord/lib/active_record/connection_handling.rb
+++ b/activerecord/lib/active_record/connection_handling.rb
@@ -109,15 +109,19 @@ module ActiveRecord
if database && role
raise ArgumentError, "connected_to can only accept a database or role argument, but not both arguments."
elsif database
- database = { database => database } if database.is_a?(Symbol)
- database.each do |role, database_key|
- config_hash = resolve_config_for_connection(database_key)
- handler = lookup_connection_handler(role.to_sym)
-
- with_handler(role.to_sym) do
- handler.establish_connection(config_hash)
- return yield
- end
+ if database.is_a?(Hash)
+ role, database = database.first
+ role = role.to_sym
+ else
+ role = database.to_sym
+ end
+
+ config_hash = resolve_config_for_connection(database)
+ handler = lookup_connection_handler(role)
+
+ with_handler(role) do
+ handler.establish_connection(config_hash)
+ yield
end
elsif role
with_handler(role.to_sym, &blk)