Skip to content

Commit

Permalink
refactor collapse_wheres method so that string based where clauses ar…
Browse files Browse the repository at this point in the history
…e handled
  • Loading branch information
jorgevaldivia committed Feb 11, 2015
1 parent 5542266 commit c12a784
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/squeel/adapters/active_record/relation_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c12a784

Please sign in to comment.