protected function maxDepthFromRelations(array $relations)
    {

        if (!$relations) {
            return 1;
        }

        $max = 1;

        foreach ($relations as $path) {
            $max = max($max, count(explode('.', $path)));
        }

        // max has to be relation depth +1 because we want to have the
        // keys of that relation too
        return (int)$max + 1;

    }