aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-06-29 14:46:57 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2014-06-29 14:46:57 -0700
commit374958b6debd03f5ce4dc0bd2071f3bc9baef330 (patch)
tree9fbbe411402a6efec4b14a737fb829fc357be0ee /activerecord
parentd9827ca49fdfc4f1771a3644e737dd67e2e168c3 (diff)
parent7a3d76b3cbd5d4705bb850b434243215db3ad688 (diff)
downloadrails-374958b6debd03f5ce4dc0bd2071f3bc9baef330.tar.gz
rails-374958b6debd03f5ce4dc0bd2071f3bc9baef330.tar.bz2
rails-374958b6debd03f5ce4dc0bd2071f3bc9baef330.zip
Merge pull request #15976 from sgrif/sg-attribute-exists
Don't encourage usage of `columns_hash`
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>,