From eb6cee9cf7fd7c22fe3190e2660eeefdd5ec651f Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Fri, 30 May 2014 09:05:18 -0700 Subject: Rename attribute related instance variables to better express intent `@attributes` was actually used for `_before_type_cast` and friends, while `@attributes_cache` is the type cast version (and caching is the wrong word there, but I'm working on removing the conditionals around that). I opted for `@raw_attributes`, because `_before_type_cast` is also semantically misleading. The values in said hash are in the state given by the form builder or database, so raw seemed to be a good word. --- activerecord/lib/active_record/persistence.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'activerecord/lib/active_record/persistence.rb') diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index b74e340b3e..78ae05073a 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -179,8 +179,8 @@ module ActiveRecord # So any change to the attributes in either instance will affect the other. def becomes(klass) became = klass.new + became.instance_variable_set("@raw_attributes", @raw_attributes) became.instance_variable_set("@attributes", @attributes) - became.instance_variable_set("@attributes_cache", @attributes_cache) became.instance_variable_set("@changed_attributes", @changed_attributes) if defined?(@changed_attributes) became.instance_variable_set("@new_record", new_record?) became.instance_variable_set("@destroyed", destroyed?) @@ -396,11 +396,11 @@ module ActiveRecord self.class.unscoped { self.class.find(id) } end - @attributes.update(fresh_object.instance_variable_get('@attributes')) + @raw_attributes.update(fresh_object.instance_variable_get('@raw_attributes')) @column_types = self.class.column_types @column_types_override = fresh_object.instance_variable_get('@column_types_override') - @attributes_cache = {} + @attributes = {} self end @@ -490,7 +490,7 @@ 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 = @attributes.keys) + def _update_record(attribute_names = @raw_attributes.keys) attributes_values = arel_attributes_with_values_for_update(attribute_names) if attributes_values.empty? 0 @@ -501,7 +501,7 @@ module ActiveRecord # Creates a record with values matching those of the instance attributes # and returns its id. - def _create_record(attribute_names = @attributes.keys) + def _create_record(attribute_names = @raw_attributes.keys) attributes_values = arel_attributes_with_values_for_create(attribute_names) new_id = self.class.unscoped.insert attributes_values -- cgit v1.2.3