提交 50823452 编写于 作者: A Aaron Patterson

remove bind values for where clauses that were removed

上级 d2d5f15f
......@@ -99,13 +99,15 @@ def merge_joins
end
def merge_multi_values
rhs_wheres = values[:where] || []
lhs_wheres = relation.where_values
rhs_wheres = values[:where] || []
lhs_binds = relation.bind_values
rhs_binds = values[:bind] || []
_, kept = partition_overwrites(lhs_wheres, rhs_wheres)
removed, kept = partition_overwrites(lhs_wheres, rhs_wheres)
relation.where_values = kept + rhs_wheres
relation.bind_values = merged_binds
relation.bind_values = filter_binds(lhs_binds, removed) + rhs_binds
if values[:reordering]
# override any order specified in the original relation
......@@ -128,12 +130,9 @@ def merge_single_values
end
end
def merged_binds
if values[:bind]
(relation.bind_values + values[:bind]).uniq(&:first)
else
relation.bind_values
end
def filter_binds(lhs_binds, removed_wheres)
set = Set.new removed_wheres.map { |x| x.left.name }
lhs_binds.dup.delete_if { |col,_| set.include? col.name }
end
# Remove equalities from the existing relation with a LHS which is
......
......@@ -1546,4 +1546,14 @@ def __omg__
assert merged.to_sql.include?("wtf")
assert merged.to_sql.include?("bbq")
end
def test_merging_removes_rhs_bind_parameters
left = Post.where(id: Arel::Nodes::BindParam.new('?'))
column = Post.columns_hash['id']
left.bind_values += [[column, 20]]
right = Post.where(id: 10)
merged = left.merge(right)
assert_equal [], merged.bind_values
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册