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

Associations not using the right shard (possibly related to Kaminari) #495

Open
dvandersluis opened this issue Jun 25, 2018 · 0 comments
Open

Comments

@dvandersluis
Copy link

I'm not sure if this can be reproduced without kaminari, but it might be able to be. The following worked on 0.8.5 and does not on 0.9.2.

class User < ActiveRecord::Base
  has_many :posts
end

user = User.using(:shard1).find(id) # assume this returns a record with posts
user.posts.page(1).tap do
  # what I do in here doesn't really matter
end

On 0.8.5, this would run the following:

[Shard: shard1]  Post Load (2.0ms)  SELECT  "posts".* FROM "posts" WHERE "posts"."user_id" = $1 LIMIT 10
=> #<ActiveRecord::AssociationRelation [#<Post id: ...>]>

However, on 0.9.2:

[Shard: master]  Post Load (2.0ms)  SELECT  "posts".* FROM "posts" WHERE "posts"."user_id" = $1 LIMIT 10
=> []

Note how it's now using the wrong shard where it used to be using the right shard.

One work around I found is this:

user.posts.using(:shard1).page(1).tap { ... }

but this means I have to set the shard multiple times where I didn't used to have to. Therefore, updating to 0.9.2 broke working code.

@dvandersluis dvandersluis changed the title Issue with kaminari and tap Associations not using the right shard (possibly related to Kaminari) Jun 27, 2018
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