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

Changeset 5259

Show
Ignore:
Timestamp:
10/09/06 02:05:50 (3 years ago)
Author:
david
Message:

Docfix (closes #6040)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/associations.rb

    r5254 r5259  
    279279    # This works by using a type column in addition to a foreign key to specify the associated record.  In the Asset example, you'd need 
    280280    # an attachable_id integer column and an attachable_type string column. 
     281    # 
     282    # Using polymorphic associations in combination with single table inheritance (STI) is a little tricky. In order 
     283    # for the associations to work as expected, ensure that you store the base model for the STI models in the  
     284    # type column of the polymorphic association. To continue with the asset example above, suppose there are guest posts 
     285    # and member posts that use the posts table for STI. So there will be an additional 'type' column in the posts table. 
     286    # 
     287    #   class Asset < ActiveRecord::Base 
     288    #     belongs_to :attachable, :polymorphic => true 
     289    #      
     290    #     def attachable_type=(sType) 
     291    #        super(sType.to_s.classify.constantize.base_class.to_s) 
     292    #     end 
     293    #   end 
     294    #  
     295    #   class Post < ActiveRecord::Base 
     296    #     # because we store "Post" in attachable_type now :dependent => :destroy will work 
     297    #     has_many :assets, :as => :attachable, :dependent => :destroy 
     298    #   end 
     299    # 
     300    #   class GuestPost < ActiveRecord::Base 
     301    #   end 
     302    # 
     303    #   class MemberPost < ActiveRecord::Base 
     304    #   end 
    281305    # 
    282306    # == Caching