nette/database

Method analyzeForeignKeys and strtolower

Closed this issue · 0 comments

Look at the Structure.php at the method analyzeForeginKeys. I guess there should be strtolower in isset and uksort lines. Otherwise columns (for tables with uppercase names) will not be properly sorted.

Current (Nette 2.3.9):

protected function analyzeForeignKeys(& $structure, $table)
{
    foreach ($this->connection->getSupplementalDriver()->getForeignKeys($table) as $row) {
        $structure['belongsTo'][strtolower($table)][$row['local']] = $row['table'];
        $structure['hasMany'][strtolower($row['table'])][$table][] = $row['local'];
    }

    if (isset($structure['belongsTo'][$table])) {
        uksort($structure['belongsTo'][$table], function ($a, $b) {
            return strlen($a) - strlen($b);
        });
    }
}

Fixed:

protected function analyzeForeignKeys(& $structure, $table)
{
    foreach ($this->connection->getSupplementalDriver()->getForeignKeys($table) as $row) {
        $structure['belongsTo'][strtolower($table)][$row['local']] = $row['table'];
        $structure['hasMany'][strtolower($row['table'])][$table][] = $row['local'];
    }

    if (isset($structure['belongsTo'][strtolower($table)])) {
        uksort($structure['belongsTo'][strtolower($table)], function ($a, $b) {
            return strlen($a) - strlen($b);
        });
    }
}