aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2018-02-26 11:16:10 -0700
committerSean Griffin <sean@seantheprogrammer.com>2018-02-26 11:21:03 -0700
commit948b931925febac3c965ab13470065ced68f7b53 (patch)
treec6236159b8a1d1c061acf6541f775400fbc60bef /activerecord/lib/active_record/persistence.rb
parent8a79d04e4dd7f0fc3c03fca905f86c03bc91ab11 (diff)
downloadrails-948b931925febac3c965ab13470065ced68f7b53.tar.gz
rails-948b931925febac3c965ab13470065ced68f7b53.tar.bz2
rails-948b931925febac3c965ab13470065ced68f7b53.zip
Never attempt to write virtual attributes to the database
Currently the place where we limit what gets sent to the database is in the implementation for `partial_writes`. We should also be restricting it to column names when partial writes are turned off. Note that we're using `&` instead of just defaulting to `self.class.column_names`, as the instance version of `attribute_names` does not include attributes which are uninitialized (were not included in the select clause)
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 88b971327b..0b1000fcf9 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -703,7 +703,8 @@ module ActiveRecord
# Updates the associated record with values matching those of the instance attributes.
# Returns the number of affected rows.
- def _update_record(attribute_names = self.attribute_names)
+ def _update_record(attribute_names = self.column_names)
+ attribute_names &= self.class.column_names
attributes_values = arel_attributes_with_values_for_update(attribute_names)
if attributes_values.empty?
rows_affected = 0
@@ -721,6 +722,7 @@ module ActiveRecord
# Creates a record with values matching those of the instance attributes
# and returns its id.
def _create_record(attribute_names = self.attribute_names)
+ attribute_names &= self.class.column_names
attributes_values = arel_attributes_with_values_for_create(attribute_names)
new_id = self.class._insert_record(attributes_values)