From feaa3e6271671d677ad95264518844fdebc3aeb5 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Sun, 19 Jun 2022 20:42:21 +0200 Subject: [PATCH] conventions: fix ManyHasMany keys lookup on MySql with different key casing [closes #578] --- src/Mapper/Dbal/Conventions/Conventions.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Mapper/Dbal/Conventions/Conventions.php b/src/Mapper/Dbal/Conventions/Conventions.php index 1eae2f9c..8eb1c36d 100644 --- a/src/Mapper/Dbal/Conventions/Conventions.php +++ b/src/Mapper/Dbal/Conventions/Conventions.php @@ -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; @@ -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; + } } }