Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/Doctrine/ORM/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,4 +936,24 @@ public function setDefaultQueryHint($name, $value)
{
$this->_attributes['defaultQueryHints'][$name] = $value;
}

/**
* Gets a list of entity class names to be ignored by the SchemaTool
*
* @return string[]
*/
public function getSchemaIgnoreClasses() : array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to make the naming a bit more precise, otherwise everything else is great. What do you think of get/setEntitiesIgnoredDuringSchemaGeneration. I first thought it should be classes instead of entities, but embeddables and other non-entities are skipped already, so its really about skipping entities here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'm happy with that. Apologies for the delay, just committed the changes here so fingers crossed.

{
return isset($this->_attributes['schemaIgnoreClasses']) === true ? $this->_attributes['schemaIgnoreClasses'] : [];
}

/**
* Sets a list of entity class names to be ignored by the SchemaTool
*
* @param string[] $schemaIgnoreClasses Array of entity class names
*/
public function setSchemaIgnoreClasses(array $schemaIgnoreClasses)
{
$this->_attributes['schemaIgnoreClasses'] = $schemaIgnoreClasses;
}
}
12 changes: 6 additions & 6 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Doctrine\ORM\ORMException;
use Doctrine\ORM\Tools\Event\GenerateSchemaTableEventArgs;
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
use function in_array;

/**
* The SchemaTool is a tool to create/drop/update database schemas based on
Expand Down Expand Up @@ -119,19 +120,18 @@ public function getCreateSchemaSql(array $classes)
/**
* Detects instances of ClassMetadata that don't need to be processed in the SchemaTool context.
*
* @param ClassMetadata $class
* @param array $processedClasses
* @param ClassMetadata $class
* @param ClassMetadata[] $processedClasses
*
* @return bool
*/
private function processingNotRequired($class, array $processedClasses)
{
return (
isset($processedClasses[$class->name]) ||
return isset($processedClasses[$class->name]) ||
$class->isMappedSuperclass ||
$class->isEmbeddedClass ||
($class->isInheritanceTypeSingleTable() && $class->name != $class->rootEntityName)
);
($class->isInheritanceTypeSingleTable() && $class->name !== $class->rootEntityName) ||
in_array($class->name, $this->em->getConfiguration()->getSchemaIgnoreClasses());
}

/**
Expand Down
28 changes: 28 additions & 0 deletions tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,34 @@ public function testDerivedCompositeKey() : void
self::assertSame($foreignColumns, $foreignKey->getForeignColumns());
}
}

/**
* @group schema-configuration
*/
public function testConfigurationSchemaIgnoredEntity() : void
{
$em = $this->_getTestEntityManager();
$schemaTool = new SchemaTool($em);

$classes = [
$em->getClassMetadata(FirstEntity::class),
$em->getClassMetadata(SecondEntity::class),
];

$schema = $schemaTool->getSchemaFromMetadata($classes);

self::assertTrue($schema->hasTable('first_entity'), 'Table first_entity should exist.');
self::assertTrue($schema->hasTable('second_entity'), 'Table second_entity should exist.');

$em->getConfiguration()->setSchemaIgnoreClasses([
SecondEntity::class,
]);

$schema = $schemaTool->getSchemaFromMetadata($classes);

self::assertTrue($schema->hasTable('first_entity'), 'Table first_entity should exist.');
self::assertFalse($schema->hasTable('second_entity'), 'Table second_entity should not exist.');
}
}

/**
Expand Down