aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-01-25 17:48:11 -0700
committerSean Griffin <sean@thoughtbot.com>2015-01-25 17:50:24 -0700
commitfcb95d67440d7e296dfeaa343ecf67a05216dca0 (patch)
tree607dfb51a8e8f90c379aed18d82ff00d5e4352c8
parent4b71ab089ce57cf063005f014e1ff1bb675c46c7 (diff)
downloadrails-fcb95d67440d7e296dfeaa343ecf67a05216dca0.tar.gz
rails-fcb95d67440d7e296dfeaa343ecf67a05216dca0.tar.bz2
rails-fcb95d67440d7e296dfeaa343ecf67a05216dca0.zip
Correct the implementation for `unscope(:where)`
The code assumes that non-single-value methods mean multi value methods. That is not the case. We need to change the accessor name, and only assign an array for multi value methods
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 1568064e18..807de3fc9f 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -900,16 +900,19 @@ module ActiveRecord
raise ArgumentError, "Called unscope() with invalid unscoping argument ':#{scope}'. Valid arguments are :#{VALID_UNSCOPING_VALUES.to_a.join(", :")}."
end
- single_val_method = Relation::SINGLE_VALUE_METHODS.include?(scope)
- unscope_code = "#{scope}_value#{'s' unless single_val_method}="
+ clause_method = Relation::CLAUSE_METHODS.include?(scope)
+ multi_val_method = Relation::MULTI_VALUE_METHODS.include?(scope)
+ if clause_method
+ unscope_code = "#{scope}_clause="
+ else
+ unscope_code = "#{scope}_value#{'s' if multi_val_method}="
+ end
case scope
when :order
result = []
- when :where
- self.bind_values = []
else
- result = [] unless single_val_method
+ result = [] if multi_val_method
end
self.send(unscope_code, result)