Forum: Ruby on Rails acts_as_tree wierdness with children.count and children.size

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
M Daggett (Guest)
on 2006-03-25 21:51
(Received via mailing list)
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 =

puts cat.children.size                             2
puts cat.children_count                          2

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

what gives?

Oliver L. (Guest)
on 2006-03-25 21:54
(Received via mailing list)
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.

Oliver L. (Guest)
on 2006-03-25 21:57
(Received via mailing list)
OK, didn't read the subject fully. You are using acts_as_tree and it
isn't working. Now I have no idea. Sorry.

This topic is locked and can not be replied to.