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) |
|---|
-
lib/active_record/associations.rb
old new 809 809 # destroyed. This requires that a column named <tt>#{table_name}_count</tt> (such as +comments_count+ for a belonging +Comment+ class) 810 810 # is used on the associate class (such as a +Post+ class). You can also specify a custom counter cache column by providing 811 811 # 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. 812 814 # Note: Specifying a counter_cache will add it to that model's list of readonly attributes using #attr_readonly. 813 815 # * <tt>:include</tt> - specify second-order associations that should be eager loaded when this object is loaded. 814 816 # Not allowed if the association is polymorphic. … … 824 826 # :conditions => 'discounts > #{payments_count}' 825 827 # belongs_to :attachable, :polymorphic => true 826 828 # belongs_to :project, :readonly => true 829 # belongs_to :post, :counter_cache => true 827 830 def belongs_to(association_id, options = {}) 828 831 reflection = create_belongs_to_reflection(association_id, options) 829 832