class method
self.current_role
Ruby on Rails 6.1.7.10
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 208
def self.current_role
if ActiveRecord::Base.legacy_connection_handling
connection_handlers.key(connection_handler) || default_role
else
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_classes)
end
default_role
end
end
Defined in activerecord/lib/active_record/core.rb line 208
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Core