Answers for "how to make a parent child relationship in a rails model using just one model"

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 "how to make a parent child relationship in a rails model using just one model"

Browse Popular Code Answers by Language