Answers for "Building Parent/Child Relationship in Rails"

0

parent child relationship rails

def get_ancestors(level = 0, result = [])
  result.push([level, self])
  if(!self.children.empty?)
    self.children.each do |child|
      child.get_ancestors(level+1, result)
    end
  end
  if(level == 0)
    return result
  end
end
Posted by: Guest on December-22-2020

Code answers related to "Building Parent/Child Relationship in Rails"

Browse Popular Code Answers by Language