public function getChildRecords(string $table, array $ids = [], $maxLevels = null, string $key = 'id', array $children = [], int $level = 0): array
    {
        if (null === ($tree = $this->getTreeCache($table, $key))) {
            return $this->database->getChildRecords($ids, $table);
        }

        foreach ($ids as $i => $id) {
            if (!isset($tree[$id]) || !\is_array($tree[$id])) {
                continue;
            }

            $children = array_merge($children, $tree[$id]);

            if (1 === $maxLevels) {
                continue;
            }

            if ($maxLevels > 0 && $level > $maxLevels) {
                return [];
            }

            if (!empty($nested = self::getChildRecords($table, $tree[$id], $maxLevels, $key, $children, ++$level))) {
                $children = $nested;
            } else {
                $depth = 0;
            }
        }

        return $children;
    }