aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
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>,