Skip to content

Commit

Permalink
pass where values to the helper function rather than rely on internal…
Browse files Browse the repository at this point in the history
… state
  • Loading branch information
tenderlove committed May 21, 2013
1 parent 3b266bc commit 658e9e0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions activerecord/lib/active_record/relation/merger.rb
Expand Up @@ -137,19 +137,19 @@ def merged_wheres
if values[:where].empty? || relation.where_values.empty? if values[:where].empty? || relation.where_values.empty?
relation.where_values + values[:where] relation.where_values + values[:where]
else else
sanitized_wheres + values[:where] sanitized_wheres(relation.where_values, values[:where]) + values[:where]
end end
end end


# Remove equalities from the existing relation with a LHS which is # Remove equalities from the existing relation with a LHS which is
# present in the relation being merged in. # present in the relation being merged in.
def sanitized_wheres def sanitized_wheres(lhs_wheres, rhs_wheres)
seen = Set.new seen = Set.new
values[:where].each do |w| rhs_wheres.each do |w|
seen << w.left if w.respond_to?(:operator) && w.operator == :== seen << w.left if w.respond_to?(:operator) && w.operator == :==
end end


relation.where_values.reject do |w| lhs_wheres.reject do |w|
w.respond_to?(:operator) && w.operator == :== && seen.include?(w.left) w.respond_to?(:operator) && w.operator == :== && seen.include?(w.left)
end end
end end
Expand Down

0 comments on commit 658e9e0

Please sign in to comment.