1
0
mirror of synced 2024-12-13 22:56:04 +03:00

[DDC-2059] Fix column and foreign key interfering with each other during reverse engineering.

This commit is contained in:
Benjamin Eberlei 2012-10-05 20:00:12 +02:00
parent fd28624120
commit 44c0ca4d3c
2 changed files with 29 additions and 0 deletions

View File

@ -297,6 +297,10 @@ class DatabaseDriver implements MappingDriver
$associationMapping['fieldName'] = $this->getFieldNameForColumn($tableName, $localColumn, true); $associationMapping['fieldName'] = $this->getFieldNameForColumn($tableName, $localColumn, true);
$associationMapping['targetEntity'] = $this->getClassNameForTable($foreignTable); $associationMapping['targetEntity'] = $this->getClassNameForTable($foreignTable);
if (isset($metadata->fieldMappings[$associationMapping['fieldName']])) {
$associationMapping['fieldName'] = $associationMapping['fieldName'] . "2";
}
if ($primaryKeyColumns && in_array($localColumn, $primaryKeyColumns)) { if ($primaryKeyColumns && in_array($localColumn, $primaryKeyColumns)) {
$associationMapping['id'] = true; $associationMapping['id'] = true;
} }

View File

@ -22,6 +22,31 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_sm = $this->_em->getConnection()->getSchemaManager(); $this->_sm = $this->_em->getConnection()->getSchemaManager();
} }
/**
* @group DDC-2059
*/
public function testIssue2059()
{
if (!$this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
$this->markTestSkipped('Platform does not support foreign keys.');
}
$user = new \Doctrine\DBAL\Schema\Table("ddc2059_user");
$user->addColumn('id', 'integer');
$user->setPrimaryKey(array('id'));
$project = new \Doctrine\DBAL\Schema\Table("ddc2059_project");
$project->addColumn('id', 'integer');
$project->addColumn('user_id', 'integer');
$project->addColumn('user', 'string');
$project->setPrimaryKey(array('id'));
$project->addForeignKeyConstraint('ddc2059_user', array('user_id'), array('id'));
$metadata = $this->convertToClassMetadata(array($project, $user), array());
$this->assertTrue(isset($metadata['Ddc2059Project']->fieldMappings['user']));
$this->assertTrue(isset($metadata['Ddc2059Project']->associationMappings['user2']));
}
public function testLoadMetadataFromDatabase() public function testLoadMetadataFromDatabase()
{ {
if (!$this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) { if (!$this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {