class ActiveRecord::Relation::Merger

def partition_overwrites(lhs_wheres, rhs_wheres)

returns [things_to_remove, things_to_keep]
present in the relation being merged in.
Remove equalities from the existing relation with a LHS which is
def partition_overwrites(lhs_wheres, rhs_wheres)
  if lhs_wheres.empty? || rhs_wheres.empty?
    return [[], lhs_wheres]
  end
  nodes = rhs_wheres.find_all do |w|
    w.respond_to?(:operator) && w.operator == :==
  end
  seen = Set.new(nodes) { |node| node.left }
  lhs_wheres.partition do |w|
    w.respond_to?(:operator) && w.operator == :== && seen.include?(w.left)
  end
end