# Counter\_cache is not looking for children\_count with acts\_as

**URL:** <https://www.ruby-forum.com/t/counter-cache-is-not-looking-for-children-count-with-acts-as/62798>\
**Category:** Rails\
**Created:** [June 8, 2006, 6:55am UTC](https://www.ruby-forum.com/t/counter-cache-is-not-looking-for-children-count-with-acts-as/62798 "2006-06-08T06:55:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwigal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6a8cbe/32.png) [@jwigal](https://www.ruby-forum.com/u/jwigal)\
**Post date:** [June 8, 2006, 6:55am UTC](https://www.ruby-forum.com/t/counter-cache-is-not-looking-for-children-count-with-acts-as/62798/1 "2006-06-08T06:55:18Z")

</div>

Hi there, the acts\_as\_tree API says that I can set a counter cache and  
that it will automatically increment the “children\_count” column. I  
did that but when I create a new page it asks for a “pages\_count”  
column instead.

Here is the relevant part of page.rb model:

class Page \< ActiveRecord::Base  
acts\_as\_tree :order =\> :position, :counter\_cache =\> true  
acts\_as\_list :scope =\> :parent\_id  
end

And here is what happens when I create a new page:

Mysql::Error: #42S22Unknown column ‘pages\_count’ in ‘field list’:  
UPDATE pages SET pages\_count = pages\_count + 1 WHERE (id = 2)

Any ideas why it’s not asking for “children\_count”?

Jeff

---

<div class="post-metadata">

**Author:** ![jwigal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6a8cbe/32.png) [@jwigal](https://www.ruby-forum.com/u/jwigal)\
**Post date:** [June 21, 2006, 6:40pm UTC](https://www.ruby-forum.com/t/counter-cache-is-not-looking-for-children-count-with-acts-as/62798/2 "2006-06-21T18:40:53Z")

</div>

hi Jeff,  
i’m noticing the same problem, have you by any chance figured it out?

:franc

---

<div class="post-metadata">

**Author:** ![jwigal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6a8cbe/32.png) [@jwigal](https://www.ruby-forum.com/u/jwigal)\
**Post date:** [June 21, 2006, 7:08pm UTC](https://www.ruby-forum.com/t/counter-cache-is-not-looking-for-children-count-with-acts-as/62798/3 "2006-06-21T19:08:50Z")

</div>

ok, to answer my own question.  
from [http://dev.rubyonrails.org/ticket/1576](http://dev.rubyonrails.org/ticket/1576)

> >

04/07/06 10:56:38: Modified by Frodo L.  
I was also a little confused by this, by thinking it was the name of the  
table, but it isn’t.

according to reflection.rb the name is made up like this:

```
        def counter_cache_column

            if options[:counter_cache] == true

                "#{active_record.name.underscore.pluralize}_count"

            elsif options[:counter_cache]

                options[:counter_cache]

            end

        end

```

that means if you set :counter\_cache =\> true it uses a pluralized  
version of the class name.

If you set :counter\_cache =\> “whatever\_counts” it uses the  
“whatever\_counts” column for counting.

Hope it helps.

> >
