Quantcast
Channel: User BvuRVKyUVlViVIc7 - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Answer by BvuRVKyUVlViVIc7 for How to connect to primary database and shards using Rails 6.1 multiple databases ActiveRecord::ConnectionHandling?

$
0
0

In general it's absolutely fine to switch connections with an around filter, we have been doing this for years (even before Rails 6) in my previous company.

Btw: did you see that the guide is mentioning your posted exception?

Note that connected_to with a role will look up an existing connection and switch using the connection specification name. This means that if you pass an unknown role like connected_to(role: :nonexistent) you will get an error that says ActiveRecord::ConnectionNotEstablished (No connection pool for 'ActiveRecord::Base' found for the 'nonexistent' role.)

https://guides.rubyonrails.org/active_record_multiple_databases.html#using-manual-connection-switching


Viewing all articles
Browse latest Browse all 42

Trending Articles