Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added clarification stating the counter_cache attribute needs to be created on the associate class via a migration #5113

Closed
wants to merge 1 commit into from

2 participants

@bsodmike

Hi all,

I only updated the comment for :counter_cache. Hopefully this should provide an elucidation to newcomers (to Rails and the :counter_cache option itself)

Thanks, M.

@bsodmike

@vijaydev Apologies, should have pushed this to lifo/docrails.

@vijaydev vijaydev closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 21, 2012
  1. @bsodmike

    added clarification stating the counter_cache attribute needs to be c…

    bsodmike authored
    …reated on the associate class via a migration
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 3 deletions.
  1. +4 −3 activerecord/lib/active_record/associations.rb
View
7 activerecord/lib/active_record/associations.rb
@@ -1382,9 +1382,10 @@ def has_one(name, options = {})
# and +decrement_counter+. The counter cache is incremented when an object of this
# class is created and decremented when it's destroyed. This requires that a column
# named <tt>#{table_name}_count</tt> (such as +comments_count+ for a belonging Comment class)
- # is used on the associate class (such as a Post class). You can also specify a custom counter
- # cache column by providing a column name instead of a +true+/+false+ value to this
- # option (e.g., <tt>:counter_cache => :my_custom_counter</tt>.)
+ # is used on the associate class (such as a Post class) - that is the migration for <tt>#{table_name}_count</tt>
+ # is created on the associate class (such that Post.comments_count will return the count cached, see note below).
+ # You can also specify a custom counter cache column by providing a column name instead of a +true+/+false+
+ # value to this option (e.g., <tt>:counter_cache => :my_custom_counter</tt>.)
# Note: Specifying a counter cache will add it to that model's list of readonly attributes
# using +attr_readonly+.
# [:include]
Something went wrong with that request. Please try again.