class method
self.current_role
Ruby on Rails 8.1.2
Since v6.1.7.10Signature
self.current_role()
Returns the symbol representing the current connected role.
ActiveRecord::Base.connected_to(role: :writing) do ActiveRecord::Base.current_role #=> :writing end ActiveRecord::Base.connected_to(role: :reading) do ActiveRecord::Base.current_role #=> :reading end
Source
# File activerecord/lib/active_record/core.rb, line 158
def self.current_role
connected_to_stack.reverse_each do |hash|
return hash[:role] if hash[:role] && hash[:klasses].include?(Base)
return hash[:role] if hash[:role] && hash[:klasses].include?(connection_class_for_self)
end
default_role
end
Defined in activerecord/lib/active_record/core.rb line 158
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Core