src/MVQN/Data/Models/Model.php
private static function getForeignKeys(string $table): array
    {
        if (self::$foreignKeysCache !== null && array_key_exists($table, self::$foreignKeysCache))
            return self::$foreignKeysCache[$table];

        // Ensure the database is connected!
        $pdo = Database::connect();

        /** @noinspection SqlResolve */
        $query = "
            SELECT
                tc.constraint_name, tc.table_name, kcu.column_name, 
                ccu.table_name AS foreign_table_name,
                ccu.column_name AS foreign_column_name 
            FROM 
                information_schema.table_constraints AS tc 
                JOIN information_schema.key_column_usage AS kcu
                  ON tc.constraint_name = kcu.constraint_name
                JOIN information_schema.constraint_column_usage AS ccu
                  ON ccu.constraint_name = tc.constraint_name
            WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '$table'
        ";

        self::$foreignKeysCache[$table] = [];

        $rows = $pdo->query($query);
        while($row = $rows->fetch())
            self::$foreignKeysCache[$table][$row["column_name"]] = $row;

        return self::$foreignKeysCache[$table];
    }
private static function getForeignKeys(string $table): array
    {
        if (self::$foreignKeysCache !== null && array_key_exists($table, self::$foreignKeysCache))
            return self::$foreignKeysCache[$table];

        // Ensure the database is connected!
        $pdo = Database::connect();

        /** @noinspection SqlResolve */
        $query = "
            SELECT
                tc.constraint_name, tc.table_name, kcu.column_name, 
                ccu.table_name AS foreign_table_name,
                ccu.column_name AS foreign_column_name 
            FROM 
                information_schema.table_constraints AS tc 
                JOIN information_schema.key_column_usage AS kcu
                  ON tc.constraint_name = kcu.constraint_name
                JOIN information_schema.constraint_column_usage AS ccu
                  ON ccu.constraint_name = tc.constraint_name
            WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '$table'
        ";

        self::$foreignKeysCache[$table] = [];

        $rows = $pdo->query($query);
        while($row = $rows->fetch())
            self::$foreignKeysCache[$table][$row["column_name"]] = $row;

        return self::$foreignKeysCache[$table];
    }
Gets an array of FOREIGN KEY columns for the specified table.

@param string $table The table name to inspect.
@return array Returns an array of information pertaining to the FOREIGN KEYs of the specified table.
@throws DatabaseConnectionException