aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2011-05-15 14:19:09 -0400
committerPrem Sichanugrist <s@sikachu.com>2011-05-15 19:07:40 -0400
commit5ca67eca21d2adfb418f96b63e7d3de237737a1e (patch)
treecda804ef476e426d94f5410df63d34abe3af935b /activerecord/lib
parentdde82a44d702f8416905476bbea5842157d6a508 (diff)
downloadrails-5ca67eca21d2adfb418f96b63e7d3de237737a1e.tar.gz
rails-5ca67eca21d2adfb418f96b63e7d3de237737a1e.tar.bz2
rails-5ca67eca21d2adfb418f96b63e7d3de237737a1e.zip
Add ActiveRecord::attribute_names to retrieve a list of attribute names. This method will also return an empty array on an abstract class or a model that the table doesn't exists.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/base.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index e1bf2ccc8a..cfe6d8d2de 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -767,6 +767,14 @@ module ActiveRecord #:nodoc:
super || (table_exists? && column_names.include?(attribute.to_s.sub(/=$/, '')))
end
+ def attribute_names
+ @attribute_names ||= if !abstract_class? && table_exists?
+ column_names
+ else
+ []
+ end
+ end
+
# Set the lookup ancestors for ActiveModel.
def lookup_ancestors #:nodoc:
klass = self