-
Notifications
You must be signed in to change notification settings - Fork 26
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
"where" doesn't work when on_shard (Rails 3.2) #6
Comments
It works if I set default_shard earlier $ be rails c
Loading development environment (Rails 3.2.14)
1.9.3-p429 :001 > ActiveRecord::Base.default_shard = 1
=> 1
1.9.3-p429 :002 > ActiveRecord::Base.on_shard(1){ Project.where(:id => 1) }
Project Load (0.3ms) SELECT `projects`.* FROM `projects` WHERE `projects`.`id` = 1
=> [] |
What's probably happening here is that the call to 'where' is returning an active relation object, ie a "promise" that is then evaluated outside the block (probably when irb calls "to_s") on it. Unfortunately, at that point we've already switched off the shard again. On Sep 2, 2013, at 1:13 PM, Lukasz Krystkowiak [email protected] wrote:
|
You're right, it works as expected when it's evaluated inside the block 1.9.3-p429 :001 > ActiveRecord::Base.on_shard(1){ Project.where(:id => 1).first }
Project Load (0.3ms) SELECT `projects`.* FROM `projects` WHERE `projects`.`id` = 1 LIMIT 1
=> nil |
re-opening, since this is very violiating of principle of least surprises -- any ideas on what it would take to stash the shard-selection alongside the activerelation promise object and switch in and out of the shard for the duration of the query? |
Something like what I did for the old ticket archive. |
ActiveRecordShards tries to read from not sharded database when calling
Steps to reproduce:
$ bundle exec rails g model Project name:string
$ bundle exec rake db:migrate
$ bundle exec rails c
Am I missing something obvious here?
The text was updated successfully, but these errors were encountered: