Browse files

explicitly anding queries of the same column

  • Loading branch information...
1 parent 149c3d6 commit 41c35abed778a7a03e7a9c14009321cd6bc11c26 @tenderlove tenderlove committed Feb 16, 2011
View
2 activerecord/lib/active_record/relation/query_methods.rb
@@ -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
View
13 activerecord/test/cases/relations_test.rb
@@ -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

0 comments on commit 41c35ab

Please sign in to comment.