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

Ticket #11172: active_record_counter_cache_doc_patch.diff

File active_record_counter_cache_doc_patch.diff, 1.5 kB (added by jardeon, 8 months ago)

Counter cache documentation update.

  • lib/active_record/associations.rb

    old new  
    809809      #   destroyed. This requires that a column named <tt>#{table_name}_count</tt> (such as +comments_count+ for a belonging +Comment+ class) 
    810810      #   is used on the associate class (such as a +Post+ class). You can also specify a custom counter cache column by providing 
    811811      #   a column name instead of a +true+/+false+ value to this option (e.g., <tt>:counter_cache => :my_custom_counter</tt>.) 
     812      #   When creating a counter cache column, the database statement or migration must specify a default value of <tt>0</tt>, failing to do  
     813      #   this results in a counter with NULL value, which will never increment. 
    812814      #   Note: Specifying a counter_cache will add it to that model's list of readonly attributes using #attr_readonly. 
    813815      # * <tt>:include</tt>  - specify second-order associations that should be eager loaded when this object is loaded. 
    814816      #   Not allowed if the association is polymorphic. 
     
    824826      #              :conditions => 'discounts > #{payments_count}' 
    825827      #   belongs_to :attachable, :polymorphic => true 
    826828      #   belongs_to :project, :readonly => true 
     829      #   belongs_to :post, :counter_cache => true 
    827830      def belongs_to(association_id, options = {}) 
    828831        reflection = create_belongs_to_reflection(association_id, options) 
    829832