Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active Record Relation delaying query till after switching to default shard #647

Open
maxstudener opened this issue May 6, 2020 · 0 comments

Comments

@maxstudener
Copy link

Steps to reproduce

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`

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):

  config.use_schemas = true
  config.seed_after_create = true
  • Rails (or ActiveRecord) version: 5.2.2

  • Ruby version: 2.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant