Skip to content

Method analyzeForeignKeys and strtolower #122

@ondrej-tuhacek

Description

@ondrej-tuhacek

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);
        });
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions