aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/attribute_methods/dirty.rb2
-rw-r--r--activerecord/lib/active_record/attributes.rb7
2 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb
index d5702accaf..ce7f575150 100644
--- a/activerecord/lib/active_record/attribute_methods/dirty.rb
+++ b/activerecord/lib/active_record/attribute_methods/dirty.rb
@@ -134,7 +134,7 @@ module ActiveRecord
# Serialized attributes should always be written in case they've been
# changed in place.
def keys_for_partial_write
- changed
+ changed & persistable_attribute_names
end
def _field_changed?(attr, old_value)
diff --git a/activerecord/lib/active_record/attributes.rb b/activerecord/lib/active_record/attributes.rb
index aafb990bc1..b263a89d79 100644
--- a/activerecord/lib/active_record/attributes.rb
+++ b/activerecord/lib/active_record/attributes.rb
@@ -9,6 +9,8 @@ module ActiveRecord
class_attribute :user_provided_defaults, instance_accessor: false # :internal:
self.user_provided_columns = {}
self.user_provided_defaults = {}
+
+ delegate :persistable_attribute_names, to: :class
end
module ClassMethods # :nodoc:
@@ -96,6 +98,10 @@ module ActiveRecord
@columns_hash ||= Hash[columns.map { |c| [c.name, c] }]
end
+ def persistable_attribute_names # :nodoc:
+ @persistable_attribute_names ||= connection.schema_cache.columns_hash(table_name).keys
+ end
+
def reset_column_information # :nodoc:
super
clear_caches_calculated_from_columns
@@ -130,6 +136,7 @@ module ActiveRecord
@columns_hash = nil
@content_columns = nil
@default_attributes = nil
+ @persistable_attribute_names = nil
end
def raw_default_values