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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
51f10739fd903d3b57561a15e4598954?d=identicon&s=25 M Daggett (Guest)
on 2006-03-25 20: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 = 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
0f1e2ec122971063c71677aa03bfe038?d=identicon&s=25 Oliver Legg (Guest)
on 2006-03-25 20: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.

Olly
0f1e2ec122971063c71677aa03bfe038?d=identicon&s=25 Oliver Legg (Guest)
on 2006-03-25 20: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.

Olly
This topic is locked and can not be replied to.