Answer the question
In order to leave comments, you need to log in
Recursion in Ruby. How to implement?
Let's say there is a model of departments with a "master - child" relationship:
District
id
id_parent
Answer the question
In order to leave comments, you need to log in
Monsieur wishes strange))
def walk_tree(root_id)
root_item = Distinct.find(root_id)
items = Distinct.where(parent_id: root_item.id)
items.each { |item| walk_tree(item.id) }
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question