|
4 | 4 |
|
5 | 5 | namespace Doctrine\ORM\Mapping\Driver; |
6 | 6 |
|
| 7 | +use Doctrine\DBAL\Schema\AbstractAsset; |
7 | 8 | use Doctrine\DBAL\Schema\AbstractSchemaManager; |
8 | 9 | use Doctrine\DBAL\Schema\Column; |
9 | 10 | use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
10 | 11 | use Doctrine\DBAL\Schema\Index; |
11 | 12 | use Doctrine\DBAL\Schema\Index\IndexedColumn; |
12 | 13 | use Doctrine\DBAL\Schema\Index\IndexType; |
13 | 14 | use Doctrine\DBAL\Schema\Name\UnqualifiedName; |
| 15 | +use Doctrine\DBAL\Schema\NamedObject; |
14 | 16 | use Doctrine\DBAL\Schema\PrimaryKeyConstraint; |
15 | 17 | use Doctrine\DBAL\Schema\SchemaException; |
16 | 18 | use Doctrine\DBAL\Schema\Table; |
@@ -143,14 +145,14 @@ public function setTables(array $entityTables, array $manyToManyTables): void |
143 | 145 | $this->tables = $this->manyToManyTables = $this->classToTableNames = []; |
144 | 146 |
|
145 | 147 | foreach ($entityTables as $table) { |
146 | | - $className = $this->getClassNameForTable($table->getName()); |
| 148 | + $className = $this->getClassNameForTable(self::getAssetName($table)); |
147 | 149 |
|
148 | | - $this->classToTableNames[$className] = $table->getName(); |
149 | | - $this->tables[$table->getName()] = $table; |
| 150 | + $this->classToTableNames[$className] = self::getAssetName($table); |
| 151 | + $this->tables[self::getAssetName($table)] = $table; |
150 | 152 | } |
151 | 153 |
|
152 | 154 | foreach ($manyToManyTables as $table) { |
153 | | - $this->manyToManyTables[$table->getName()] = $table; |
| 155 | + $this->manyToManyTables[self::getAssetName($table)] = $table; |
154 | 156 | } |
155 | 157 | } |
156 | 158 |
|
@@ -219,13 +221,13 @@ public function loadMetadataForClass(string $className, PersistenceClassMetadata |
219 | 221 | $localColumn = current(self::getReferencingColumnNames($myFk)); |
220 | 222 |
|
221 | 223 | $associationMapping = []; |
222 | | - $associationMapping['fieldName'] = $this->getFieldNameForColumn($manyTable->getName(), current(self::getReferencingColumnNames($otherFk)), true); |
| 224 | + $associationMapping['fieldName'] = $this->getFieldNameForColumn(self::getAssetName($manyTable), current(self::getReferencingColumnNames($otherFk)), true); |
223 | 225 | $associationMapping['targetEntity'] = $this->getClassNameForTable(self::getReferencedTableName($otherFk)); |
224 | 226 |
|
225 | | - if (current($manyTable->getColumns())->getName() === $localColumn) { |
226 | | - $associationMapping['inversedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current(self::getReferencingColumnNames($myFk)), true); |
| 227 | + if (self::getAssetName(current($manyTable->getColumns())) === $localColumn) { |
| 228 | + $associationMapping['inversedBy'] = $this->getFieldNameForColumn(self::getAssetName($manyTable), current(self::getReferencingColumnNames($myFk)), true); |
227 | 229 | $associationMapping['joinTable'] = [ |
228 | | - 'name' => strtolower($manyTable->getName()), |
| 230 | + 'name' => strtolower(self::getAssetName($manyTable)), |
229 | 231 | 'joinColumns' => [], |
230 | 232 | 'inverseJoinColumns' => [], |
231 | 233 | ]; |
@@ -270,7 +272,7 @@ private function reverseEngineerMappingFromDatabase(): void |
270 | 272 | $this->tables = $this->manyToManyTables = $this->classToTableNames = []; |
271 | 273 |
|
272 | 274 | foreach ($this->sm->listTables() as $table) { |
273 | | - $tableName = $table->getName(); |
| 275 | + $tableName = self::getAssetName($table); |
274 | 276 | $foreignKeys = $table->getForeignKeys(); |
275 | 277 |
|
276 | 278 | $allForeignKeyColumns = []; |
@@ -335,7 +337,7 @@ private function buildIndexes(ClassMetadata $metadata): void |
335 | 337 | $isUnique = $index->isUnique(); |
336 | 338 | } |
337 | 339 |
|
338 | | - $indexName = $index->getName(); |
| 340 | + $indexName = self::getAssetName($index); |
339 | 341 | $indexColumns = self::getIndexedColumns($index); |
340 | 342 | $constraintType = $isUnique |
341 | 343 | ? 'uniqueConstraints' |
@@ -364,13 +366,13 @@ private function buildFieldMappings(ClassMetadata $metadata): void |
364 | 366 | $fieldMappings = []; |
365 | 367 |
|
366 | 368 | foreach ($columns as $column) { |
367 | | - if (in_array($column->getName(), $allForeignKeys, true)) { |
| 369 | + if (in_array(self::getAssetName($column), $allForeignKeys, true)) { |
368 | 370 | continue; |
369 | 371 | } |
370 | 372 |
|
371 | 373 | $fieldMapping = $this->buildFieldMapping($tableName, $column); |
372 | 374 |
|
373 | | - if ($primaryKeys && in_array($column->getName(), $primaryKeys, true)) { |
| 375 | + if ($primaryKeys && in_array(self::getAssetName($column), $primaryKeys, true)) { |
374 | 376 | $fieldMapping['id'] = true; |
375 | 377 | $ids[] = $fieldMapping; |
376 | 378 | } |
@@ -411,8 +413,8 @@ private function buildFieldMappings(ClassMetadata $metadata): void |
411 | 413 | private function buildFieldMapping(string $tableName, Column $column): array |
412 | 414 | { |
413 | 415 | $fieldMapping = [ |
414 | | - 'fieldName' => $this->getFieldNameForColumn($tableName, $column->getName(), false), |
415 | | - 'columnName' => $column->getName(), |
| 416 | + 'fieldName' => $this->getFieldNameForColumn($tableName, self::getAssetName($column), false), |
| 417 | + 'columnName' => self::getAssetName($column), |
416 | 418 | 'type' => Type::getTypeRegistry()->lookupName($column->getType()), |
417 | 419 | 'nullable' => ! $column->getNotnull(), |
418 | 420 | 'options' => [ |
@@ -619,4 +621,12 @@ private static function getPrimaryKey(Table $table): Index|null |
619 | 621 |
|
620 | 622 | return null; |
621 | 623 | } |
| 624 | + |
| 625 | + private static function getAssetName(AbstractAsset $asset): string |
| 626 | + { |
| 627 | + return $asset instanceof NamedObject |
| 628 | + ? $asset->getObjectName()->toString() |
| 629 | + // DBAL < 4.4 |
| 630 | + : $asset->getName(); |
| 631 | + } |
622 | 632 | } |
0 commit comments