Skip to content

Commit

Permalink
conventions: fix ManyHasMany keys lookup on MySql with different key …
Browse files Browse the repository at this point in the history
…casing [closes #578]
  • Loading branch information
hrach committed Jun 19, 2022
1 parent 4ac33cf commit feaa3e6
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Mapper/Dbal/Conventions/Conventions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Nextras\Dbal\Bridges\NetteCaching\CachedPlatform;
use Nextras\Dbal\IConnection;
use Nextras\Dbal\Platforms\Data\Table;
use Nextras\Dbal\Platforms\MySqlPlatform;
use Nextras\Orm\Entity\Embeddable\EmbeddableContainer;
use Nextras\Orm\Entity\Reflection\EntityMetadata;
use Nextras\Orm\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -318,14 +319,24 @@ protected function findManyHasManyPrimaryColumns(string $joinTable, Table $targe
$targetTable = $targetTableReflection->getNameFqn();
$sourceId = $targetId = null;

$isCaseSensitive = $this->platform->getName() !== MySqlPlatform::NAME;

$keys = $this->platform->getForeignKeys($joinTable);
foreach ($keys as $column => $meta) {
$refTable = $meta->getRefTableFqn();

if ($refTable === $sourceTable && $sourceId === null) {
$sourceId = $column;
} elseif ($refTable === $targetTable) {
$targetId = $column;
if ($isCaseSensitive) {
if ($refTable === $sourceTable && $sourceId === null) {
$sourceId = $column;
} elseif ($refTable === $targetTable) {
$targetId = $column;
}
} else {
if (strcasecmp($refTable, $sourceTable) === 0 && $sourceId === null) {
$sourceId = $column;
} elseif (strcasecmp($refTable, $targetTable) === 0) {
$targetId = $column;
}
}
}

Expand Down

0 comments on commit feaa3e6

Please sign in to comment.