Skip to content

Commit

Permalink
#7841 fix issue
Browse files Browse the repository at this point in the history
Also add skip for DDC-2138 for non-fk-supporting platforms
  • Loading branch information
vpArth committed Sep 30, 2019
1 parent 6a15b37 commit e0855c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,25 +737,26 @@ private function gatherRelationJoinColumns(

$compositeName = $theJoinTable->getName() . '.' . implode('', $localColumns);

if (isset($addedFks[$compositeName])
&& ($foreignTableName !== $addedFks[$compositeName]['foreignTableName']
|| 0 < count(array_diff($foreignColumns, $addedFks[$compositeName]['foreignColumns'])))
) {
if ($this->platform->supportsForeignKeyConstraints()) {
if (isset($addedFks[$compositeName])
&& ($foreignTableName !== $addedFks[$compositeName]['foreignTableName']
|| 0 < count(array_diff($foreignColumns, $addedFks[$compositeName]['foreignColumns'])))
) {
foreach ($theJoinTable->getForeignKeys() as $fkName => $key) {
if (count(array_diff($key->getLocalColumns(), $localColumns)) === 0
&& (($key->getForeignTableName() !== $foreignTableName)
|| 0 < count(array_diff($key->getForeignColumns(), $foreignColumns)))
|| 0 < count(array_diff($key->getForeignColumns(), $foreignColumns)))
) {
$theJoinTable->removeForeignKey($fkName);
break;
}
}

$blacklistedFks[$compositeName] = true;
} elseif (! isset($blacklistedFks[$compositeName])) {
} elseif (!isset($blacklistedFks[$compositeName])) {
$addedFks[$compositeName] = [
'foreignTableName' => $foreignTableName,
'foreignColumns' => $foreignColumns,
'foreignColumns' => $foreignColumns,
];

$theJoinTable->addForeignKeyConstraint(
Expand All @@ -764,6 +765,7 @@ private function gatherRelationJoinColumns(
$foreignColumns,
$fkOptions
);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class DDC2138Test extends OrmFunctionalTestCase
*/
public function testForeignKeyOnSTIWithMultipleMapping() : void
{
if (!$this->em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
$this->markTestSkipped('Platform does not support foreign keys.');
}
$schema = $this->schemaTool->getSchemaFromMetadata(
[
$this->em->getClassMetadata(DDC2138User::class),
Expand Down

0 comments on commit e0855c2

Please sign in to comment.