提交 4b534152 编写于 作者: S Sean Griffin

Use a bound parameter for the "id = " portion of update statements

We need to re-order the bind parameters since the AST returned by the
relation will have the where statement as the first bp, which breaks on
PG.
上级 daab7e59
......@@ -79,12 +79,18 @@ def _update_record(values, id, id_was) # :nodoc:
scope.unscope!(where: @klass.inheritance_column)
end
um = scope.where(@klass.arel_table[@klass.primary_key].eq(id_was || id)).arel.compile_update(substitutes, @klass.primary_key)
relation = scope.where(@klass.primary_key => (id_was || id))
bvs = binds + relation.bind_values
um = relation
.arel
.compile_update(substitutes, @klass.primary_key)
reorder_bind_params(um.ast, bvs)
@klass.connection.update(
um,
'SQL',
binds)
bvs,
)
end
def substitute_values(values) # :nodoc:
......
......@@ -883,12 +883,15 @@ def build_arel
# Reorder bind indexes if joins produced bind values
bvs = arel.bind_values + bind_values
arel.ast.grep(Arel::Nodes::BindParam).each_with_index do |bp, i|
reorder_bind_params(arel.ast, bvs)
arel
end
def reorder_bind_params(ast, bvs)
ast.grep(Arel::Nodes::BindParam).each_with_index do |bp, i|
column = bvs[i].first
bp.replace connection.substitute_at(column, i)
end
arel
end
def symbol_unscoping(scope)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册