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

        if (isset($tree[$id]) && 0 === $level) {
            $parents[] = $id;
        }

        foreach ($tree as $pid => $ids) {
            if (!\in_array($id, $ids)) {
                continue;
            }

            $parents[] = $pid;

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

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

            if (!empty($nested = self::getParentRecords($table, $pid, $maxLevels, $key, $parents, ++$level))) {
                $parents = $nested;
            } else {
                $level = 0;
            }
        }

        return $parents;
    }