public static function ancestry($nameOrObject, $tablesOnly = false)
    {
        if (is_string($nameOrObject) && !class_exists($nameOrObject)) {
            return [];
        }

        $class = self::class_name($nameOrObject);

        $lowerClass = strtolower($class);

        $cacheKey = $lowerClass . '_' . (string)$tablesOnly;
        $parent = $class;
        if (!isset(self::$_cache_ancestry[$cacheKey])) {
            $ancestry = [];
            do {
                if (!$tablesOnly || DataObject::getSchema()->classHasTable($parent)) {
                    $ancestry[strtolower($parent)] = $parent;
                }
            } while ($parent = get_parent_class($parent));
            self::$_cache_ancestry[$cacheKey] = array_reverse($ancestry);
        }

        return self::$_cache_ancestry[$cacheKey];
    }