Primary Keys as Foreign Keys - reverse engineering
This commit is contained in:
parent
de5e4b0fdc
commit
06eed4cfda
@ -1224,7 +1224,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
foreach ($mapping['joinColumns'] as $key => &$joinColumn) {
|
foreach ($mapping['joinColumns'] as $key => &$joinColumn) {
|
||||||
if ($mapping['type'] === self::ONE_TO_ONE && ! $this->isInheritanceTypeSingleTable()) {
|
if ($mapping['type'] === self::ONE_TO_ONE && ! $this->isInheritanceTypeSingleTable()) {
|
||||||
if (count($mapping['joinColumns']) == 1) {
|
if (count($mapping['joinColumns']) == 1) {
|
||||||
$joinColumn['unique'] = true;
|
if(! isset($mapping['id']) || ! $mapping['id'])
|
||||||
|
$joinColumn['unique'] = true;
|
||||||
} else {
|
} else {
|
||||||
$uniqueContraintColumns[] = $joinColumn['name'];
|
$uniqueContraintColumns[] = $joinColumn['name'];
|
||||||
}
|
}
|
||||||
|
@ -192,10 +192,12 @@ class DatabaseDriver implements Driver
|
|||||||
$fieldMappings = array();
|
$fieldMappings = array();
|
||||||
foreach ($columns as $column) {
|
foreach ($columns as $column) {
|
||||||
$fieldMapping = array();
|
$fieldMapping = array();
|
||||||
if ($primaryKeyColumns && in_array($column->getName(), $primaryKeyColumns)) {
|
|
||||||
$fieldMapping['id'] = true;
|
|
||||||
} else if (in_array($column->getName(), $allForeignKeyColumns)) {
|
if (in_array($column->getName(), $allForeignKeyColumns)) {
|
||||||
continue;
|
continue;
|
||||||
|
} else if ($primaryKeyColumns && in_array($column->getName(), $primaryKeyColumns)) {
|
||||||
|
$fieldMapping['id'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fieldMapping['fieldName'] = $this->getFieldNameForColumn($tableName, $column->getName(), false);
|
$fieldMapping['fieldName'] = $this->getFieldNameForColumn($tableName, $column->getName(), false);
|
||||||
@ -298,13 +300,27 @@ class DatabaseDriver implements Driver
|
|||||||
$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 ($primaryKeyColumns && in_array($localColumn, $primaryKeyColumns))
|
||||||
|
{
|
||||||
|
$associationMapping['id'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
for ($i = 0; $i < count($cols); $i++) {
|
for ($i = 0; $i < count($cols); $i++) {
|
||||||
$associationMapping['joinColumns'][] = array(
|
$associationMapping['joinColumns'][] = array(
|
||||||
'name' => $cols[$i],
|
'name' => $cols[$i],
|
||||||
'referencedColumnName' => $fkCols[$i],
|
'referencedColumnName' => $fkCols[$i],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$metadata->mapManyToOne($associationMapping);
|
|
||||||
|
|
||||||
|
//Here we need to check if $cols are the same as $primaryKeyColums
|
||||||
|
if(!array_diff($cols,$primaryKeyColumns))
|
||||||
|
$metadata->mapOneToOne($associationMapping);
|
||||||
|
else
|
||||||
|
$metadata->mapManyToOne($associationMapping);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -890,6 +890,16 @@ public function <methodName>()
|
|||||||
if ($this->_generateAnnotations) {
|
if ($this->_generateAnnotations) {
|
||||||
$lines[] = $this->_spaces . ' *';
|
$lines[] = $this->_spaces . ' *';
|
||||||
|
|
||||||
|
if (isset($associationMapping['id']) && $associationMapping['id']) {
|
||||||
|
$lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'Id';
|
||||||
|
|
||||||
|
if ($generatorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
|
||||||
|
$lines[] = $this->_spaces.' * @' . $this->_annotationsPrefix . 'GeneratedValue(strategy="' . $generatorType . '")';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$type = null;
|
$type = null;
|
||||||
switch ($associationMapping['type']) {
|
switch ($associationMapping['type']) {
|
||||||
case ClassMetadataInfo::ONE_TO_ONE:
|
case ClassMetadataInfo::ONE_TO_ONE:
|
||||||
|
Loading…
Reference in New Issue
Block a user