Hello, I have a class "ve" which acts_as_tree and has an attribute
"recommendations", which is itself another model (referenced by a
belongs_to, has_many relationship, a "ve" has many recommendations)
I wish I could get all recommendations for a specific node, knowing
that this number would be the sum of its own recommendations and those
of its children, and it's children's children and so on.
I think the best wat to do it is through a helper, but I get stuck wit
the algorithm. For exemple, if I want only to get the sum of all
recommendations present, it's easy throgh the folowing helper (which
even might be more performant, i guess)
def get_recommandations_number(node, ret)
for n in node.children
ret = get_recommandations_number(n, ret)
ret += node.recommendations.count
However, being recommendations another model, I can't get it through
the same algorithm.
I hope there's an easy way, but I am not very good with ruby.
Would anybody please help me?