From c12a7841ade2f3129540530b5e6eadf269377bcb Mon Sep 17 00:00:00 2001 From: Jorge Valdivia Date: Wed, 11 Feb 2015 15:54:00 -0600 Subject: [PATCH] refactor collapse_wheres method so that string based where clauses are handled --- lib/squeel/adapters/active_record/relation_extensions.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/squeel/adapters/active_record/relation_extensions.rb b/lib/squeel/adapters/active_record/relation_extensions.rb index 1f1fd4a..b11828b 100644 --- a/lib/squeel/adapters/active_record/relation_extensions.rb +++ b/lib/squeel/adapters/active_record/relation_extensions.rb @@ -270,14 +270,14 @@ def collapse_wheres(arel, wheres) wheres = Array(wheres) binaries = wheres.grep(Arel::Nodes::Binary) - groups = binaries.group_by {|b| [b.class, b.left]} - - arel.where(Arel::Nodes::And.new(groups.map{|_, bins| bins}.flatten)) if groups.any? + groups = binaries.group_by {|b| [b.class, b.left]}.map{|_, bins| bins}.flatten (wheres - binaries).each do |where| where = Arel.sql(where) if String === where - arel.where(Arel::Nodes::Grouping.new(where)) + groups.push(Arel::Nodes::Grouping.new(where)) end + + arel.where(Arel::Nodes::And.new(groups)) if groups.any? end def find_equality_predicates(nodes, relation_table_name = table_name)