diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-03-16 02:46:01 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-03-16 02:46:01 +0000 |
commit | def746030c20697f2c4376515169eeda2f6332b4 (patch) | |
tree | 1569968114c0c728011b450ff10ac278914f60e8 /activerecord/lib/active_record/base.rb | |
parent | 0859779d6f1cadfec12f1112c80382658466ab7d (diff) | |
download | rails-def746030c20697f2c4376515169eeda2f6332b4.tar.gz rails-def746030c20697f2c4376515169eeda2f6332b4.tar.bz2 rails-def746030c20697f2c4376515169eeda2f6332b4.zip |
Added Base.abstract_class? that marks which classes are not part of the Active Record hierarchy. closes #3704
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3882 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 8c1f615a37..a4505733de 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -599,7 +599,7 @@ module ActiveRecord #:nodoc: end def reset_table_name - name = "#{table_name_prefix}#{undecorated_table_name(class_name_of_active_record_descendant(self))}#{table_name_suffix}" + name = "#{table_name_prefix}#{undecorated_table_name(base_class.name)}#{table_name_suffix}" set_table_name(name) name end @@ -614,9 +614,9 @@ module ActiveRecord #:nodoc: key = 'id' case primary_key_prefix_type when :table_name - key = Inflector.foreign_key(class_name_of_active_record_descendant(self), false) + key = Inflector.foreign_key(base_class.name, false) when :table_name_with_underscore - key = Inflector.foreign_key(class_name_of_active_record_descendant(self)) + key = Inflector.foreign_key(base_class.name) end set_primary_key(key) key @@ -936,7 +936,15 @@ module ActiveRecord #:nodoc: class_of_active_record_descendant(self) end - + # Set this to true if this is an abstract class (see #abstract_class?). + attr_accessor :abstract_class + + # Returns whether this class is a base AR class. If A is a base class and + # B descends from A, then B.base_class will return B. + def abstract_class? + abstract_class == true + end + private # Finder methods must instantiate through this method to work with the single-table inheritance model # that makes it possible to create objects of different types from the same table. @@ -1016,7 +1024,7 @@ module ActiveRecord #:nodoc: end # Guesses the table name, but does not decorate it with prefix and suffix information. - def undecorated_table_name(class_name = class_name_of_active_record_descendant(self)) + def undecorated_table_name(class_name = base_class.name) table_name = Inflector.underscore(Inflector.demodulize(class_name)) table_name = Inflector.pluralize(table_name) if pluralize_table_names table_name @@ -1172,7 +1180,7 @@ module ActiveRecord #:nodoc: # Returns the class descending directly from ActiveRecord in the inheritance hierarchy. def class_of_active_record_descendant(klass) - if klass.superclass == Base + if klass.superclass == Base || klass.superclass.abstract_class? klass elsif klass.superclass.nil? raise ActiveRecordError, "#{name} doesn't belong in a hierarchy descending from ActiveRecord" @@ -1183,7 +1191,7 @@ module ActiveRecord #:nodoc: # Returns the name of the class descending directly from ActiveRecord in the inheritance hierarchy. def class_name_of_active_record_descendant(klass) - class_of_active_record_descendant(klass).name + klass.base_class.name end # Accepts an array or string. The string is returned untouched, but the array has each value |