Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

explicitly anding queries of the same column

  • Loading branch information...
commit 41c35abed778a7a03e7a9c14009321cd6bc11c26 1 parent 149c3d6
Aaron Patterson tenderlove authored
2  activerecord/lib/active_record/relation/query_methods.rb
View
@@ -206,7 +206,7 @@ def collapse_wheres(arel, wheres)
groups.each do |_, eqls|
test = eqls.inject(eqls.shift) do |memo, expr|
- memo.or(expr)
+ memo.and(expr)
end
arel = arel.where(test)
end
13 activerecord/test/cases/relations_test.rb
View
@@ -465,10 +465,17 @@ def test_find_all_using_where_twice_should_or_the_relation
relation = relation.where(:name => david.name)
relation = relation.where(:name => 'Santiago')
relation = relation.where(:id => david.id)
- assert_equal [david], relation.all
+ assert_equal [], relation.all
end
- def test_find_all_with_multiple_ors
+ def test_multi_where_ands_queries
+ relation = Author.unscoped
+ david = authors(:david)
+ sql = relation.where(:name => david.name).where(:name => 'Santiago').to_sql
+ assert_match('AND', sql)
+ end
+
+ def test_find_all_with_multiple_should_use_and
david = authors(:david)
relation = [
{ :name => david.name },
@@ -477,7 +484,7 @@ def test_find_all_with_multiple_ors
].inject(Author.unscoped) do |memo, param|
memo.where(param)
end
- assert_equal [david], relation.all
+ assert_equal [], relation.all
end
def test_exists
Please sign in to comment.
Something went wrong with that request. Please try again.