Acts_as_tree wierdness with children.count and children.size

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?


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.


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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs