diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-23 09:48:47 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-23 09:54:06 -0600 |
commit | ae96f229f6501d8635811d6b22d75d43cdb880a4 (patch) | |
tree | 57d224d09a4617f74b3ef980cf92173806765020 /activerecord/lib/active_record/attribute_methods.rb | |
parent | 936fd4c1e017ec88699b3cd7daa09847da36c731 (diff) | |
download | rails-ae96f229f6501d8635811d6b22d75d43cdb880a4.tar.gz rails-ae96f229f6501d8635811d6b22d75d43cdb880a4.tar.bz2 rails-ae96f229f6501d8635811d6b22d75d43cdb880a4.zip |
Add a deprecation cycle for `NullColumn` from `column_for_attribute`
This is public API, and `simple_form` depends on the `nil` return value.
We need to go through a deprecation cycle to return a null object. If
people want hash access, they can access the hash.
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 267377cec6..51f6a009db 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -186,8 +186,7 @@ module ActiveRecord end # Returns the column object for the named attribute. - # Returns a +ActiveRecord::ConnectionAdapters::NullColumn+ if the - # named attribute does not exist. + # Returns nil if the named attribute does not exist. # # class Person < ActiveRecord::Base # end @@ -197,12 +196,17 @@ module ActiveRecord # # => #<ActiveRecord::ConnectionAdapters::SQLite3Column:0x007ff4ab083980 @name="name", @sql_type="varchar(255)", @null=true, ...> # # person.column_for_attribute(:nothing) - # # => #<ActiveRecord::ConnectionAdapters::NullColumn:0xXXX @name=nil, @sql_type=nil, @cast_type=#<Type::Value>, ...> + # # => nil def column_for_attribute(name) - name = name.to_s - columns_hash.fetch(name) do - ConnectionAdapters::NullColumn.new(name) + column = columns_hash[name.to_s] + if column.nil? + ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc) + `column_for_attribute` will return a null object for non-existent columns + in Rails 5.0. If you would like to continue to receive `nil`, you should + instead call `model.class.columns_hash[name]` + MESSAGE end + column end end |