# Acts\_as\_tree counter\_cache behavior is different than API do

**URL:** <https://www.ruby-forum.com/t/acts-as-tree-counter-cache-behavior-is-different-than-api-do/53393>\
**Category:** Rails\
**Created:** [February 3, 2006, 7:34pm UTC](https://www.ruby-forum.com/t/acts-as-tree-counter-cache-behavior-is-different-than-api-do/53393 "2006-02-03T19:34:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DSTaylor\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b38774/32.png) [@DSTaylor\_S](https://www.ruby-forum.com/u/DSTaylor_S)\
**Post date:** [February 3, 2006, 7:34pm UTC](https://www.ruby-forum.com/t/acts-as-tree-counter-cache-behavior-is-different-than-api-do/53393/1 "2006-02-03T19:34:54Z")

</div>

Before I file a ticket, I’ll query ya’ll about this:

The API docs for acts\_as\_tree’s counter\_cache is to create a database  
column  
called “children\_count” to hold the counter\_cache. I have enabled this  
option in my model. While writing tests I wrote a test for creating  
children  
from the a parent:  
message = @forum\_message[“parent”].find  
child = message.children.create( “member\_id” =\> 1, “forum\_id” =\> 1,  
“subject” =\> ‘another subject’, “body” =\> “good grief.”)

This follows the the API docs pretty closely at  
[http://ar.rubyonrails.com/classes/ActiveRecord/Acts/Tree/ClassMethods.html](http://ar.rubyonrails.com/classes/ActiveRecord/Acts/Tree/ClassMethods.html)

However, the test fails for this reason:

1. Error:  
test\_proper\_creation\_of\_message\_reply(ForumMessageTest):  
ActiveRecord::StatementInvalid: PGError: ERROR: column  
“forum\_messages\_count” does not exist  
: UPDATE forum\_message SET forum\_messages\_count = forum\_messages\_count +  
1  
WHERE (id = 1)

The docs do not mention creating a table column based on the model name.  
Is  
this the now intended behavior?

Where is it documented and can the name of the column be overridden?

Thank you for any help.

D. Taylor S.

---

<div class="post-metadata">

**Author:** ![DSTaylor\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b38774/32.png) [@DSTaylor\_S](https://www.ruby-forum.com/u/DSTaylor_S)\
**Post date:** [February 3, 2006, 11:21pm UTC](https://www.ruby-forum.com/t/acts-as-tree-counter-cache-behavior-is-different-than-api-do/53393/2 "2006-02-03T23:21:45Z")

</div>

On Feb 3, 2006, at 10:33 AM, D. Taylor S. wrote:

> This follows the the API docs pretty closely at http://
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

D-

```
I ran into the same problem using acts_as_tree to make a small forum

```

I wrote. You do have to name the \*\_count column after the tablename  
you use it in for things to work correctly. Not sure if the docs are  
just wrong or what.

Cheers  
-Ezra Z.  
Yakima Herald-Republic  
WebMaster

> **[yakimaherald.com | Yakima, Washington - We Tell Your Stories](https://www.yakimaherald.com/)**

509-577-7732  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![DSTaylor\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b38774/32.png) [@DSTaylor\_S](https://www.ruby-forum.com/u/DSTaylor_S)\
**Post date:** [February 3, 2006, 11:49pm UTC](https://www.ruby-forum.com/t/acts-as-tree-counter-cache-behavior-is-different-than-api-do/53393/3 "2006-02-03T23:49:09Z")

</div>

Thanks for the response. I’ll go ahead and file a ticket to fix the  
documentation then.

D. Taylor S.
