Skip to content

Commit

Permalink
Removed completeRuntimeMetadata() method from ClassMetadataFactory an…
Browse files Browse the repository at this point in the history
…d moved to the appropriate location
  • Loading branch information
guilhermeblanco committed Jul 3, 2019
1 parent 0476201 commit 906c146
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 36 deletions.
7 changes: 4 additions & 3 deletions lib/Doctrine/ORM/Mapping/Builder/TableMetadataBuilder.php
Expand Up @@ -44,9 +44,10 @@ public function build() : Mapping\TableMetadata
assert($this->entityClassMetadata !== null);

$namingStrategy = $this->metadataBuildingContext->getNamingStrategy();
$tableMetadata = new Mapping\TableMetadata();

$tableMetadata->setName($namingStrategy->classToTableName($this->entityClassMetadata->getClassName()));
$tableName = $this->tableAnnotation !== null && ! empty($this->tableAnnotation->name)
? $this->tableAnnotation->name
: $namingStrategy->classToTableName($this->entityClassMetadata->getClassName());
$tableMetadata = new Mapping\TableMetadata($tableName);

if ($this->tableAnnotation === null) {
return $tableMetadata;
Expand Down
18 changes: 18 additions & 0 deletions lib/Doctrine/ORM/Mapping/ClassMetadata.php
Expand Up @@ -1119,6 +1119,24 @@ public function setTable(TableMetadata $table) : void
if (empty($table->getName())) {
$table->setName($this->namingStrategy->classToTableName($this->className));
}

// Make sure inherited and declared properties reflect newly defined table
foreach ($this->declaredProperties as $property) {
switch (true) {
case $property instanceof FieldMetadata:
$property->setTableName($property->getTableName() ?? $table->getName());
break;

case $property instanceof ToOneAssociationMetadata:
// Resolve association join column table names
foreach ($property->getJoinColumns() as $joinColumn) {
/** @var JoinColumnMetadata $joinColumn */
$joinColumn->setTableName($joinColumn->getTableName() ?? $table->getName());
}

break;
}
}
}

/**
Expand Down
33 changes: 0 additions & 33 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Expand Up @@ -390,7 +390,6 @@ protected function doLoadMetadata(
$classMetadata = $this->driver->loadMetadataForClass($className, $parent, $metadataBuildingContext);

$this->completeIdentifierGeneratorMappings($classMetadata);
$this->completeRuntimeMetadata($classMetadata, $parent);

if ($this->evm->hasListeners(Events::loadClassMetadata)) {
$eventArgs = new LoadClassMetadataEventArgs($classMetadata, $this->em);
Expand All @@ -404,38 +403,6 @@ protected function doLoadMetadata(
return $classMetadata;
}

protected function completeRuntimeMetadata(ClassMetadata $class, ?ClassMetadata $parent = null) : void
{
if (! $parent || ! $parent->isMappedSuperclass) {
return;
}

if ($class->isMappedSuperclass) {
return;
}

$tableName = $class->getTableName();

// Resolve column table names
foreach ($class->getDeclaredPropertiesIterator() as $property) {
if ($property instanceof FieldMetadata) {
$property->setTableName($property->getTableName() ?? $tableName);

continue;
}

if (! ($property instanceof ToOneAssociationMetadata)) {
continue;
}

// Resolve association join column table names
foreach ($property->getJoinColumns() as $joinColumn) {
/** @var JoinColumnMetadata $joinColumn */
$joinColumn->setTableName($joinColumn->getTableName() ?? $tableName);
}
}
}

/**
* Validate runtime metadata is correctly defined.
*
Expand Down

0 comments on commit 906c146

Please sign in to comment.