diff --git a/lib/replica_pools/active_record_extensions.rb b/lib/replica_pools/active_record_extensions.rb index ebd58bb..1513628 100644 --- a/lib/replica_pools/active_record_extensions.rb +++ b/lib/replica_pools/active_record_extensions.rb @@ -17,6 +17,10 @@ def connection_proxy ReplicaPools.proxy end + def with_connection_proxy + yield ReplicaPools.proxy + end + # Make sure transactions run on leader # Even if they're initiated from ActiveRecord::Base # (which doesn't have our hijack). diff --git a/lib/replica_pools/hijack.rb b/lib/replica_pools/hijack.rb index 8bfe9de..1d92f04 100644 --- a/lib/replica_pools/hijack.rb +++ b/lib/replica_pools/hijack.rb @@ -18,6 +18,7 @@ def inherited(child) def hijack_connection class << self alias_method :connection, :connection_proxy + alias_method :with_connection, :with_connection_proxy end end end