# Acts\_as\_tree wierdness with children.count and children.size

**URL:** <https://www.ruby-forum.com/t/acts-as-tree-wierdness-with-children-count-and-children-size/87176>\
**Category:** Rails\
**Created:** [March 25, 2006, 8:51pm UTC](https://www.ruby-forum.com/t/acts-as-tree-wierdness-with-children-count-and-children-size/87176 "2006-03-25T20:51:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_Daggett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@M\_Daggett](https://www.ruby-forum.com/u/M_Daggett)\
**Post date:** [March 25, 2006, 8:51pm UTC](https://www.ruby-forum.com/t/acts-as-tree-wierdness-with-children-count-and-children-size/87176/1 "2006-03-25T20:51:17Z")

</div>

i am making a category tree and i iterate over the category using my  
counter\_cache however it would show a different number than what was  
actually being represetned in the tree.

Here is an example

cat.children = [cat2, cat3]

puts cat.children.size 2  
puts cat.children\_count 2

cat4.parent\_id = cat.id  
cat4.save

puts cat.children.size 2  
puts cat.children\_count 2

however cat.children.count produces the correct number (3)

what gives?

Thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![M\_Daggett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@M\_Daggett](https://www.ruby-forum.com/u/M_Daggett)\
**Post date:** [March 25, 2006, 8:54pm UTC](https://www.ruby-forum.com/t/acts-as-tree-wierdness-with-children-count-and-children-size/87176/2 "2006-03-25T20:54:24Z")

</div>

I think you might have to do something like cat.reload to refresh the  
data. I also think that there is a plugin called acts\_as\_tree which  
does exactly what you are describing.

Olly

---

<div class="post-metadata">

**Author:** ![M\_Daggett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@M\_Daggett](https://www.ruby-forum.com/u/M_Daggett)\
**Post date:** [March 25, 2006, 8:57pm UTC](https://www.ruby-forum.com/t/acts-as-tree-wierdness-with-children-count-and-children-size/87176/3 "2006-03-25T20:57:13Z")

</div>

OK, didn’t read the subject fully. You are using acts\_as\_tree and it  
isn’t working. Now I have no idea. Sorry.

Olly
