diff --git a/lib/identity_cache.rb b/lib/identity_cache.rb index 15fd653e..1e908a07 100644 --- a/lib/identity_cache.rb +++ b/lib/identity_cache.rb @@ -137,7 +137,7 @@ def should_use_cache? # :nodoc: # When there are no open transactions, `current_transaction` returns a # special `NullTransaction` object that is unjoinable, meaning we will # use the cache. - pool.connection.current_transaction.joinable? + connection_for(pool).current_transaction.joinable? end end @@ -257,6 +257,16 @@ def fetch_in_batches(keys, &block) result.merge!(cache.fetch_multi(*slice, &block)) end end + + if ActiveRecord.gem_version >= Gem::Version.new("7.2.0.beta1") + def connection_for(pool) + pool.lease_connection + end + else + def connection_for(pool) + pool.connection + end + end end end