explicitly allowing lolqueries

This commit is contained in:
Aaron Patterson
2011-02-16 15:11:48 -08:00
parent ceb2f0f216
commit 9c023cc4d2
2 changed files with 11 additions and 13 deletions

View File

@@ -209,16 +209,7 @@ module ActiveRecord
def collapse_wheres(arel, wheres)
equalities = wheres.grep(Arel::Nodes::Equality)
groups = equalities.group_by do |equality|
equality.left
end
groups.each do |_, eqls|
test = eqls.inject(eqls.shift) do |memo, expr|
memo.or(expr)
end
arel.where(test)
end
arel.where(Arel::Nodes::And.new(equalities)) unless equalities.empty?
(wheres - equalities).each do |where|
where = Arel.sql(where) if String === where

View File

@@ -474,10 +474,17 @@ class RelationTest < ActiveRecord::TestCase
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 },
@@ -486,7 +493,7 @@ class RelationTest < ActiveRecord::TestCase
].inject(Author.unscoped) do |memo, param|
memo.where(param)
end
assert_equal [david], relation.all
assert_equal [], relation.all
end
def test_find_all_using_where_with_relation