Acts_as_tree wierdness with children.count and children.size


#1

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


#2

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


#3

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