M Daggett
2006-Mar-25 19:51 UTC
[Rails] 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 = 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 -- -------------------------------------------------------------------- I am Mark Daggett and I approve this message. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060325/00697877/attachment.html
Oliver Legg
2006-Mar-25 19:54 UTC
[Rails] acts_as_tree wierdness with children.count and children.size
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 On 25 Mar 2006, at 19:51, M Daggett wrote:> 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 > > > > -- > -------------------------------------------------------------------- > I am Mark Daggett and I approve this message. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060325/56eedcf5/attachment.html
Oliver Legg
2006-Mar-25 19:56 UTC
[Rails] acts_as_tree wierdness with children.count and children.size
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 On 25 Mar 2006, at 19:53, Oliver Legg wrote:> 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 > > On 25 Mar 2006, at 19:51, M Daggett wrote: > >> 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 >> >> >> >> -- >> -------------------------------------------------------------------- >> I am Mark Daggett and I approve this message. >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060325/df4d6edd/attachment.html