Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass self directly to connection_class #47673

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions activerecord/lib/active_record/connection_handling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ module ConnectionHandling
# may be returned on an error.
def establish_connection(config_or_env = nil)
config_or_env ||= DEFAULT_ENV.call.to_sym
db_config, connection_class = resolve_config_for_connection(config_or_env)
connection_handler.establish_connection(db_config, owner_name: connection_class, role: current_role, shard: current_shard)
db_config = resolve_config_for_connection(config_or_env)
connection_handler.establish_connection(db_config, owner_name: self, role: current_role, shard: current_shard)
end

# Connects a model to the databases specified. The +database+ keyword
Expand Down Expand Up @@ -87,18 +87,18 @@ def connects_to(database: {}, shards: {})
connections = []

database.each do |role, database_key|
db_config, connection_class = resolve_config_for_connection(database_key)
db_config = resolve_config_for_connection(database_key)

self.connection_class = true
connections << connection_handler.establish_connection(db_config, owner_name: connection_class, role: role)
connections << connection_handler.establish_connection(db_config, owner_name: self, role: role)
end

shards.each do |shard, database_keys|
database_keys.each do |role, database_key|
db_config, connection_class = resolve_config_for_connection(database_key)
db_config = resolve_config_for_connection(database_key)

self.connection_class = true
connections << connection_handler.establish_connection(db_config, owner_name: connection_class, role: role, shard: shard.to_sym)
connections << connection_handler.establish_connection(db_config, owner_name: self, role: role, shard: shard.to_sym)
end
end

Expand Down Expand Up @@ -343,8 +343,7 @@ def resolve_config_for_connection(config_or_env)
connection_name = primary_class? ? Base.name : name
self.connection_specification_name = connection_name

db_config = Base.configurations.resolve(config_or_env)
[db_config, self]
Base.configurations.resolve(config_or_env)
end

def with_role_and_shard(role, shard, prevent_writes)
Expand Down