aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-06-29 12:51:42 -0600
committerSean Griffin <sean@thoughtbot.com>2014-06-29 12:51:42 -0600
commit7a3d76b3cbd5d4705bb850b434243215db3ad688 (patch)
tree15831100ea274a424896fb8aec70daa10c92d370 /activerecord
parent9ca0f8da2abe735c57eacd9b687ee7c3fae3685d (diff)
downloadrails-7a3d76b3cbd5d4705bb850b434243215db3ad688.tar.gz
rails-7a3d76b3cbd5d4705bb850b434243215db3ad688.tar.bz2
rails-7a3d76b3cbd5d4705bb850b434243215db3ad688.zip
Don't encourage usage of `columns_hash`
As discussed in https://github.com/plataformatec/simple_form/pull/1094, we should not encourage usage of `columns_hash`, and instead provide an alternate method to determine whether or not an attribute exists. The language `attribute` was chosen over `column` since these are in the `AttributeMethods` module.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 51f6a009db..75154a7975 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -202,12 +202,17 @@ module ActiveRecord
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]`
+ in Rails 5.0. Use `attribute_exists?` if you need to check for an
+ attribute's existence.
MESSAGE
end
column
end
+
+ # Returns whether or not an attribute exists with the given name.
+ def attribute_exists?(name)
+ @attributes.include?(name)
+ end
end
# A Person object with a name attribute can ask <tt>person.respond_to?(:name)</tt>,