Permalink
Browse files

avoid creating a set if no where values are removed

  • Loading branch information...
tenderlove committed May 21, 2013
1 parent 5082345 commit f3ebbeae6eb647767ccd49e25821b1ba33923596
Showing with 14 additions and 0 deletions.
  1. +2 −0 activerecord/lib/active_record/relation/merger.rb
  2. +12 −0 activerecord/test/cases/relations_test.rb
@@ -131,6 +131,8 @@ def merge_single_values
end
def filter_binds(lhs_binds, removed_wheres)
+ return lhs_binds if removed_wheres.empty?
+
set = Set.new removed_wheres.map { |x| x.left.name }
lhs_binds.dup.delete_if { |col,_| set.include? col.name }
end
@@ -1556,4 +1556,16 @@ def test_merging_removes_rhs_bind_parameters
merged = left.merge(right)
assert_equal [], merged.bind_values
end
+
+ def test_merging_keeps_lhs_bind_parameters
+ column = Post.columns_hash['id']
+ binds = [[column, 20]]
+
+ right = Post.where(id: Arel::Nodes::BindParam.new('?'))
+ right.bind_values += binds
+ left = Post.where(id: 10)
+
+ merged = left.merge(right)
+ assert_equal binds, merged.bind_values
+ end
end

0 comments on commit f3ebbea

Please sign in to comment.