Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6013

Show
Ignore:
Timestamp:
01/23/07 04:19:16 (2 years ago)
Author:
bitsweat
Message:

Subclasses of an abstract class work with single-table inheritance. References #5704, closes #7284.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r6012 r6013  
    11*SVN* 
     2 
     3* Subclasses of an abstract class work with single-table inheritance.  #5704, #7284 [BertG, nick+rails@ag.arizona.edu] 
    24 
    35* Make sure sqlite3 driver closes open connections on disconnect [Rob Rasmussen] 
  • trunk/activerecord/lib/active_record/base.rb

    r5913 r6013  
    818818      end 
    819819 
    820       def descends_from_active_record? # :nodoc: 
    821         superclass == Base || !columns_hash.include?(inheritance_column) 
     820      # True if this isn't a concrete subclass needing a STI type condition. 
     821      def descends_from_active_record? 
     822        if superclass.abstract_class? 
     823          superclass.descends_from_active_record? 
     824        else 
     825          superclass == Base || !columns_hash.include?(inheritance_column) 
     826        end 
    822827      end 
    823828 
  • trunk/activerecord/test/fixtures/company.rb

    r5264 r6013  
    1 class Company < ActiveRecord::Base 
     1class AbstractCompany < ActiveRecord::Base 
     2  self.abstract_class = true 
     3end 
     4 
     5class Company < AbstractCompany 
    26  attr_protected :rating 
    37  set_sequence_name :companies_nonstd_seq 
  • trunk/activerecord/test/inheritance_test.rb

    r5751 r6013  
    66class InheritanceTest < Test::Unit::TestCase 
    77  fixtures :companies, :projects, :subscribers, :accounts 
     8 
     9  def test_company_descends_from_active_record 
     10    assert_raise(NoMethodError) { ActiveRecord::Base.descends_from_active_record? } 
     11    assert AbstractCompany.descends_from_active_record?, 'AbstractCompany should descend from ActiveRecord::Base' 
     12    assert Company.descends_from_active_record?, 'Company should descend from ActiveRecord::Base' 
     13    assert !Class.new(Company).descends_from_active_record?, 'Company subclass should not descend from ActiveRecord::Base' 
     14  end 
    815 
    916  def test_a_bad_type_column