Skip to content

Commit

Permalink
#7841 SchemaTool generates extra diff for platforms without FK support
Browse files Browse the repository at this point in the history
  • Loading branch information
vpArth committed Oct 2, 2019
1 parent 167cb44 commit 3707c39
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,11 @@ private function gatherRelationJoinColumns(
}

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

if (! $this->platform->supportsForeignKeyConstraints()) {
return;
}

if (isset($addedFks[$compositeName])
&& ($foreignTableName != $addedFks[$compositeName]['foreignTableName']
|| 0 < count(array_diff($foreignColumns, $addedFks[$compositeName]['foreignColumns'])))
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 @@ -14,6 +14,9 @@ class DDC2138Test extends OrmFunctionalTestCase
public function testForeignKeyOnSTIWithMultipleMapping()
{
$em = $this->_em;
if (! $em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
$this->markTestSkipped('Platform does not support foreign keys.');
}
$schemaTool = new SchemaTool($em);

$classes = [
Expand Down
57 changes: 57 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH7841Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Tests\OrmFunctionalTestCase;

/**
* @group GH7841
*/
class GH7841Test extends OrmFunctionalTestCase
{
public function testForeignKeysNotCompare() : void
{
if ($this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
$this->markTestSkipped('Test for platforms without foreign keys support');
}
$class = $this->_em->getClassMetadata(GH7841Child::class);
$this->_schemaTool->updateSchema([$class], true);
$diff = $this->_schemaTool->getUpdateSchemaSql([$class], true);

self::assertEmpty($diff);

$this->_schemaTool->dropSchema([$class]);
}
}

/**
* @Entity
*/
class GH7841Parent
{
/** @Id @Column(type="integer") @GeneratedValue */
public $id;

/** @OneToMany(targetEntity=GH7841Child::class, mappedBy="parent") */
public $children;

public function __construct()
{
$this->children = new ArrayCollection();
}
}

/**
* @Entity
*/
class GH7841Child
{
/** @Id @Column(type="integer") @GeneratedValue */
public $id;

/** @ManyToOne(targetEntity=GH7841Parent::class) */
public $parent;
}

0 comments on commit 3707c39

Please sign in to comment.