diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-11-01 17:29:14 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-11-01 17:29:14 -0600 |
commit | 4b534152951fe9b1af8a1d3311da766e1d42392a (patch) | |
tree | 1d48c70f07d6576a38cf6f784ff20cf40e33ecc3 /activerecord/lib/active_record/relation.rb | |
parent | daab7e59a6196fa2bbab17dc4a88b095a211fc96 (diff) | |
download | rails-4b534152951fe9b1af8a1d3311da766e1d42392a.tar.gz rails-4b534152951fe9b1af8a1d3311da766e1d42392a.tar.bz2 rails-4b534152951fe9b1af8a1d3311da766e1d42392a.zip |
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.
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index a25e6e321f..03bce4f5b7 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -79,12 +79,18 @@ module ActiveRecord 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: |