diff options
author | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2018-10-11 17:54:56 -0400 |
---|---|---|
committer | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2018-10-26 16:27:25 -0400 |
commit | abf51844bb598ffdd2e6b8aa722b75b5897d9a3f (patch) | |
tree | 75adb5fce26f2c9c43614dd765af999300664b1e /activerecord/lib/active_record/connection_handling.rb | |
parent | 5431e17733366da1fd10f2cd3039d66a56012683 (diff) | |
download | rails-abf51844bb598ffdd2e6b8aa722b75b5897d9a3f.tar.gz rails-abf51844bb598ffdd2e6b8aa722b75b5897d9a3f.tar.bz2 rails-abf51844bb598ffdd2e6b8aa722b75b5897d9a3f.zip |
Add support for hash and url configs in connected_to
Add support for hash and url configs in database hash
of `ActiveRecord::Base.connected_to`.
Diffstat (limited to 'activerecord/lib/active_record/connection_handling.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_handling.rb | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb index 5141271db9..e3b59b8a22 100644 --- a/activerecord/lib/active_record/connection_handling.rb +++ b/activerecord/lib/active_record/connection_handling.rb @@ -109,12 +109,15 @@ module ActiveRecord if database && role raise ArgumentError, "connected_to can only accept a database or role argument, but not both arguments." elsif database - config_hash = resolve_config_for_connection(database) - handler = lookup_connection_handler(database.to_sym) - - with_handler(database.to_sym) do - handler.establish_connection(config_hash) - return yield + 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 end elsif role with_handler(role.to_sym, &blk) |