Skip to content

Commit

Permalink
Merge pull request #9056 from derrabus/improvement/foreign-key-get-co…
Browse files Browse the repository at this point in the history
…lumns

Remove calls to `ForeignKeyConstraint::getColumns()`
  • Loading branch information
greg0ire authored Oct 2, 2021
2 parents eb27aca + 9d4fac0 commit 149c430
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,22 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
continue;
}

$localColumn = current($myFk->getColumns());
$localColumn = current($myFk->getLocalColumns());

$associationMapping = [];
$associationMapping['fieldName'] = $this->getFieldNameForColumn($manyTable->getName(), current($otherFk->getColumns()), true);
$associationMapping['fieldName'] = $this->getFieldNameForColumn($manyTable->getName(), current($otherFk->getLocalColumns()), true);
$associationMapping['targetEntity'] = $this->getClassNameForTable($otherFk->getForeignTableName());

if (current($manyTable->getColumns())->getName() === $localColumn) {
$associationMapping['inversedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current($myFk->getColumns()), true);
$associationMapping['inversedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current($myFk->getLocalColumns()), true);
$associationMapping['joinTable'] = [
'name' => strtolower($manyTable->getName()),
'joinColumns' => [],
'inverseJoinColumns' => [],
];

$fkCols = $myFk->getForeignColumns();
$cols = $myFk->getColumns();
$cols = $myFk->getLocalColumns();

for ($i = 0, $colsCount = count($cols); $i < $colsCount; $i++) {
$associationMapping['joinTable']['joinColumns'][] = [
Expand All @@ -232,7 +232,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
}

$fkCols = $otherFk->getForeignColumns();
$cols = $otherFk->getColumns();
$cols = $otherFk->getLocalColumns();

for ($i = 0, $colsCount = count($cols); $i < $colsCount; $i++) {
$associationMapping['joinTable']['inverseJoinColumns'][] = [
Expand All @@ -241,7 +241,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
];
}
} else {
$associationMapping['mappedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current($myFk->getColumns()), true);
$associationMapping['mappedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current($myFk->getLocalColumns()), true);
}

$metadata->mapManyToMany($associationMapping);
Expand Down Expand Up @@ -454,7 +454,7 @@ private function buildToOneAssociationMappings(ClassMetadataInfo $metadata)

foreach ($foreignKeys as $foreignKey) {
$foreignTableName = $foreignKey->getForeignTableName();
$fkColumns = $foreignKey->getColumns();
$fkColumns = $foreignKey->getLocalColumns();
$fkForeignColumns = $foreignKey->getForeignColumns();
$localColumn = current($fkColumns);
$associationMapping = [
Expand Down

0 comments on commit 149c430

Please sign in to comment.