From 8ffb22056c2896a67917b813064b2247233d3a08 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 1 Dec 2006 21:24:47 +0000 Subject: Subclasses of an abstract class work with single-table inheritance. Closes #5704. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5660 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 99c276ef8b..08df7e6f2e 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -816,7 +816,7 @@ module ActiveRecord #:nodoc: end def descends_from_active_record? # :nodoc: - superclass == Base || !columns_hash.include?(inheritance_column) + superclass.abstract_class? || !columns_hash.include?(inheritance_column) end @@ -1161,7 +1161,7 @@ module ActiveRecord #:nodoc: segments = [] segments << sanitize_sql(scope[:conditions]) if scope && scope[:conditions] segments << sanitize_sql(conditions) unless conditions.nil? - segments << type_condition unless descends_from_active_record? + segments << type_condition unless descends_from_active_record? segments.compact! sql << "WHERE (#{segments.join(") AND (")}) " unless segments.empty? end @@ -1362,7 +1362,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 || klass.superclass.abstract_class? + if klass.superclass.abstract_class? klass elsif klass.superclass.nil? raise ActiveRecordError, "#{name} doesn't belong in a hierarchy descending from ActiveRecord" @@ -1483,6 +1483,9 @@ module ActiveRecord #:nodoc: end end + # ActiveRecord::Base is abstract. + self.abstract_class = true + public # New objects can be instantiated as either empty (pass no construction parameter) or pre-set with # attributes but not yet saved (pass a hash with key names matching the associated table column names). -- cgit v1.2.3