Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #10523 from neerajdotname/last-where-clause-wins

Extraction to enable fixing #10421
  • Loading branch information...
commit c0df1e8c08a27a7de489dad7492015d68f2c76f7 2 parents 05609f4 + fdba949
@jeremy jeremy authored
Showing with 12 additions and 13 deletions.
  1. +12 −13 activerecord/lib/active_record/relation/merger.rb
View
25 activerecord/lib/active_record/relation/merger.rb
@@ -139,21 +139,20 @@ def merged_wheres
if values[:where].empty? || relation.where_values.empty?
relation.where_values + values[:where]
else
- # Remove equalities from the existing relation with a LHS which is
- # present in the relation being merged in.
+ sanitized_wheres + values[:where]
+ end
+ end
- seen = Set.new
- values[:where].each { |w|
- if w.respond_to?(:operator) && w.operator == :==
- seen << w.left
- end
- }
+ # Remove equalities from the existing relation with a LHS which is
+ # present in the relation being merged in.
+ def sanitized_wheres
+ seen = Set.new
+ values[:where].each do |w|
+ seen << w.left if w.respond_to?(:operator) && w.operator == :==
+ end
- relation.where_values.reject { |w|
- w.respond_to?(:operator) &&
- w.operator == :== &&
- seen.include?(w.left)
- } + values[:where]
+ relation.where_values.reject do |w|
+ w.respond_to?(:operator) && w.operator == :== && seen.include?(w.left)
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.