instance method connecting_to

Ruby on Rails 7.1.6

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

connecting_to(role: default_role, shard: default_shard, prevent_writes: false)

Use a specified connection.

This method is useful for ensuring that a specific connection is being used. For example, when booting a console in readonly mode.

It is not recommended to use this method in a request since it does not yield to a block like connected_to.

Parameters

role key = default_role
shard key = default_shard
prevent_writes key = false
Source
# File activerecord/lib/active_record/connection_handling.rb, line 185
    def connecting_to(role: default_role, shard: default_shard, prevent_writes: false)
      prevent_writes = true if role == ActiveRecord.reading_role

      append_to_connected_to_stack(role: role, shard: shard, prevent_writes: prevent_writes, klasses: [self])
    end

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

Defined in ActiveRecord::ConnectionHandling

Type at least 2 characters to search.

↑↓ navigate · open · esc close