aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2018-10-30 12:52:23 -0600
committerSean Griffin <sean@seantheprogrammer.com>2018-10-30 12:52:23 -0600
commitb63701e272f3dc932ba7a20127f6dc82b567cfb4 (patch)
tree1eb65b792ad7835c67449c81cb6c4f1b7b4be1d3 /activerecord/lib
parent9a18a10e1cf6dd971d170f3684717c2ffe687776 (diff)
downloadrails-b63701e272f3dc932ba7a20127f6dc82b567cfb4.tar.gz
rails-b63701e272f3dc932ba7a20127f6dc82b567cfb4.tar.bz2
rails-b63701e272f3dc932ba7a20127f6dc82b567cfb4.zip
`update_columns` raises if the column is unknown
Previosly, `update_columns` would just take whatever keys you gave it and tried to run the update query. Most likely this would result in an error from the database. However, if the column actually did exist, but was in `ignored_columns`, this would result in the method returning successfully when it should have raised, and an attribute that should not exist written to `@attributes`.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/persistence.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 45ceb1e3ad..f991a3076e 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -479,15 +479,15 @@ module ActiveRecord
verify_readonly_attribute(key.to_s)
end
+ attributes.each do |k, v|
+ write_attribute_without_type_cast(k, v)
+ end
+
affected_rows = self.class._update_record(
attributes,
self.class.primary_key => id_in_database
)
- attributes.each do |k, v|
- write_attribute_without_type_cast(k, v)
- end
-
affected_rows == 1
end