Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method analyzeForeignKeys and strtolower #122

Closed
ondrej-tuhacek opened this issue Mar 14, 2016 · 0 comments
Closed

Method analyzeForeignKeys and strtolower #122

ondrej-tuhacek opened this issue Mar 14, 2016 · 0 comments

Comments

@ondrej-tuhacek
Copy link

@ondrej-tuhacek ondrej-tuhacek commented Mar 14, 2016

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);
        });
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.