You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
classUser < ActiveRecord::Basehas_many:postsenduser=User.using(:shard1).find(id)# assume this returns a record with postsuser.posts.page(1).tapdo# what I do in here doesn't really matterend
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.
The text was updated successfully, but these errors were encountered:
dvandersluis
changed the title
Issue with kaminari and tap
Associations not using the right shard (possibly related to Kaminari)
Jun 27, 2018
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.
On 0.8.5, this would run the following:
However, on 0.9.2:
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:
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.
The text was updated successfully, but these errors were encountered: