aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/query_methods.rb
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-12-07 00:49:36 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-12-07 01:06:42 -0200
commit6ba0f975d5d2867f80bcf8a809b1337c8f369383 (patch)
tree2f28f62f231bec5d035cc37f793996bad8110011 /activerecord/lib/active_record/relation/query_methods.rb
parent23b9cc84230042aaf7f824d70e010d7678350ec3 (diff)
downloadrails-6ba0f975d5d2867f80bcf8a809b1337c8f369383.tar.gz
rails-6ba0f975d5d2867f80bcf8a809b1337c8f369383.tar.bz2
rails-6ba0f975d5d2867f80bcf8a809b1337c8f369383.zip
Ensure there won't be any regression with where(nil) calls
Consider this scenario: if params[:foo] conditions = { foo: true } end foos = Foo.where(conditions).order(:id) When params[:foo] is nil, this would call: foos = Foo.where(nil).order(:id) In this scenario, we want Foo.where(conditions) to be the same as calling Foo.all, otherwise we'd get a "NoMethodError order for WhereChain". Related to #8332.
Diffstat (limited to 'activerecord/lib/active_record/relation/query_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index d197bfe946..256a7e839f 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -452,8 +452,8 @@ module ActiveRecord
#
# If the condition is any other blank-ish object than nil, then where is a # no-op and returns
# the current relation.
- def where(opts = nil, *rest)
- if opts.nil?
+ def where(opts = :chain, *rest)
+ if opts == :chain
WhereChain.new(spawn)
elsif opts.blank?
self
@@ -464,8 +464,8 @@ module ActiveRecord
# #where! is identical to #where, except that instead of returning a new relation, it adds
# the condition to the existing relation.
- def where!(opts = nil, *rest) # :nodoc:
- if opts.nil?
+ def where!(opts = :chain, *rest) # :nodoc:
+ if opts == :chain
WhereChain.new(self)
else
references!(PredicateBuilder.references(opts)) if Hash === opts