aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-06-04 11:45:53 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-06-04 11:45:53 -0700
commit1ce0cc0d38c9f5058cb484612fab625db823c4e4 (patch)
tree7c856d0c2f6534c349ff2e81a01046acaa868c31 /activerecord/lib/active_record/attribute_methods
parent3f7e482aed8f67137c6c8382f6c558d7e856b341 (diff)
parentb8f586a094c104006d29a87fee0d8b48d0af2d14 (diff)
downloadrails-1ce0cc0d38c9f5058cb484612fab625db823c4e4.tar.gz
rails-1ce0cc0d38c9f5058cb484612fab625db823c4e4.tar.bz2
rails-1ce0cc0d38c9f5058cb484612fab625db823c4e4.zip
Merge branch 'master' of github.com:rails/rails
* 'master' of github.com:rails/rails: For our build, stick with mail 2.5.x for now Correct result, previously showing wrong result Collapse PG default extractoin of most types to single regex Change wording of explanation about precision & scale of decimal numbers [ci skip] Cleaned up duplicated CHANGELOG entry [ci skip] reuse available belongs_to? method Convert StrongParameters cache to a hash. This fixes an unbounded memory leak demonstrated on @tenderlove's latest blog post: Partially revert deprecation of *_filter Pluralize params Add default_i18n_subject to the guides Fix regression on eager loading association based on SQL query rather than existing column. Relax mail gem constraint from ~> 2.5.4 to ~> 2.5, >= 2.5.4 Keep column defaults in type cast form Return a null column when no column exists for an attribute Refactor XML serializer to not depend on `serialized_attributes` Test the serialized types of virtual columns in XML implement ActiveRecord::Base#pretty_print + changelog Remove duplicated HashWithIndifferentAccess#with_indifferent_access.
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r--activerecord/lib/active_record/attribute_methods/dirty.rb3
-rw-r--r--activerecord/lib/active_record/attribute_methods/write.rb12
2 files changed, 8 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb
index 6cd4e43ddd..4e32b78e34 100644
--- a/activerecord/lib/active_record/attribute_methods/dirty.rb
+++ b/activerecord/lib/active_record/attribute_methods/dirty.rb
@@ -94,8 +94,7 @@ module ActiveRecord
end
def _field_changed?(attr, old, value)
- column = column_for_attribute(attr) || Type::Value.new
- column.changed?(old, value)
+ column_for_attribute(attr).changed?(old, value)
end
end
end
diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb
index c3e601a208..5203b30462 100644
--- a/activerecord/lib/active_record/attribute_methods/write.rb
+++ b/activerecord/lib/active_record/attribute_methods/write.rb
@@ -72,18 +72,20 @@ module ActiveRecord
@attributes.delete(attr_name)
column = column_for_attribute(attr_name)
+ unless has_attribute?(attr_name) || self.class.columns_hash.key?(attr_name)
+ raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attr_name}'"
+ end
+
# If we're dealing with a binary column, write the data to the cache
# so we don't attempt to typecast multiple times.
- if column && column.binary?
+ if column.binary?
@attributes[attr_name] = value
end
- if column && should_type_cast
+ if should_type_cast
@raw_attributes[attr_name] = column.type_cast_for_write(value)
- elsif !should_type_cast || @raw_attributes.has_key?(attr_name)
- @raw_attributes[attr_name] = value
else
- raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attr_name}'"
+ @raw_attributes[attr_name] = value
end
end
end