1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

avoid creating a set if no where values are removed

This commit is contained in:
Aaron Patterson 2013-05-21 11:01:19 -07:00
parent 50823452f7
commit f3ebbeae6e
2 changed files with 14 additions and 0 deletions

View file

@ -131,6 +131,8 @@ module ActiveRecord
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

View file

@ -1556,4 +1556,16 @@ class RelationTest < ActiveRecord::TestCase
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