instance method
prohibit_shard_swapping
Ruby on Rails 7.0.10
Since v7.0.10Signature
prohibit_shard_swapping(enabled = true)
Prohibit swapping shards while inside of the passed block.
In some cases you may want to be able to swap shards but not allow a nested call to connected_to or connected_to_many to swap again. This is useful in cases you’re using sharding to provide per-request database isolation.
Parameters
-
enabledopt = true
Source
# File activerecord/lib/active_record/connection_handling.rb, line 214
def prohibit_shard_swapping(enabled = true)
prev_value = ActiveSupport::IsolatedExecutionState[:active_record_prohibit_shard_swapping]
ActiveSupport::IsolatedExecutionState[:active_record_prohibit_shard_swapping] = enabled
yield
ensure
ActiveSupport::IsolatedExecutionState[:active_record_prohibit_shard_swapping] = prev_value
end
Defined in activerecord/lib/active_record/connection_handling.rb line 214
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::ConnectionHandling