Apartment::Tenant.switch('tenant-a-production') do
Term.all
end
(0.4ms) use `tenant-a-production`
(0.4ms) use `tenant-default-production`
Term Load (1.2ms) SELECT `terms`.* FROM `terms`
Apartment::Tenant.switch('tenant-a-production') do
Term.all.to_a
end
(0.3ms) use `tenant-a-production`
Term Load (1.0ms) SELECT `terms`.* FROM `terms`
(0.3ms) use `tenant-default-production`
Steps to reproduce
Expected behavior
Call something in active record that triggers https://apidock.com/rails/ActiveRecord/Relation/load on models before switching to default database
Actual behavior
Database switches to default tenant then executes query.
Database: MySql
Apartment version: 2.2.1
Apartment config (in
config/initializers/apartment.rb
or so):Rails (or ActiveRecord) version: 5.2.2
Ruby version: 2.5