Skip to content
This repository
Browse code

explicitly anding queries of the same column

  • Loading branch information...
commit 41c35abed778a7a03e7a9c14009321cd6bc11c26 1 parent 149c3d6
Aaron Patterson authored February 16, 2011
2  activerecord/lib/active_record/relation/query_methods.rb
@@ -206,7 +206,7 @@ def collapse_wheres(arel, wheres)
206 206
 
207 207
       groups.each do |_, eqls|
208 208
         test = eqls.inject(eqls.shift) do |memo, expr|
209  
-          memo.or(expr)
  209
+          memo.and(expr)
210 210
         end
211 211
         arel = arel.where(test)
212 212
       end
13  activerecord/test/cases/relations_test.rb
@@ -465,10 +465,17 @@ def test_find_all_using_where_twice_should_or_the_relation
465 465
     relation = relation.where(:name => david.name)
466 466
     relation = relation.where(:name => 'Santiago')
467 467
     relation = relation.where(:id => david.id)
468  
-    assert_equal [david], relation.all
  468
+    assert_equal [], relation.all
469 469
   end
470 470
 
471  
-  def test_find_all_with_multiple_ors
  471
+  def test_multi_where_ands_queries
  472
+    relation = Author.unscoped
  473
+    david = authors(:david)
  474
+    sql = relation.where(:name => david.name).where(:name => 'Santiago').to_sql
  475
+    assert_match('AND', sql)
  476
+  end
  477
+
  478
+  def test_find_all_with_multiple_should_use_and
472 479
     david = authors(:david)
473 480
     relation = [
474 481
       { :name => david.name },
@@ -477,7 +484,7 @@ def test_find_all_with_multiple_ors
477 484
     ].inject(Author.unscoped) do |memo, param|
478 485
       memo.where(param)
479 486
     end
480  
-    assert_equal [david], relation.all
  487
+    assert_equal [], relation.all
481 488
   end
482 489
 
483 490
   def test_exists

0 notes on commit 41c35ab

Please sign in to comment.
Something went wrong with that request. Please try again.