public function flatten(array $nest, array $related = array())
    {
        $children = array();
        foreach ($nest as $id => $values) {
            $parents = $related;
            $parents[] = $id;
            if (!empty($values)) {
                foreach ($this->flatten($values, $parents) as $nest) {
                    $children[] = $nest;
                }
            } else {
                $children[] = $parents;
            }
        }

        return $children;
    }