class method self.current_preventing_writes

Ruby on Rails 6.1.7.10

Since v6.1.7.10

Available in: v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

self.current_preventing_writes()

Returns the symbol representing the current setting for preventing writes.

ActiveRecord::Base.connected_to(role: :reading) do
  ActiveRecord::Base.current_preventing_writes #=> true
end

ActiveRecord::Base.connected_to(role: :writing) do
  ActiveRecord::Base.current_preventing_writes #=> false
end
Source
# File activerecord/lib/active_record/core.rb, line 249
      def self.current_preventing_writes
        if legacy_connection_handling
          connection_handler.prevent_writes
        else
          connected_to_stack.reverse_each do |hash|
            return hash[:prevent_writes] if !hash[:prevent_writes].nil? && hash[:klasses].include?(Base)
            return hash[:prevent_writes] if !hash[:prevent_writes].nil? && hash[:klasses].include?(connection_classes)
          end

          false
        end
      end

Defined in activerecord/lib/active_record/core.rb line 249 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Core

Type at least 2 characters to search.

↑↓ navigate · open · esc close