give the FQCN to the naming strategy
This commit is contained in:
parent
3fff83cd13
commit
d8227fcd06
@ -771,13 +771,13 @@ class ClassMetadataInfo implements ClassMetadata
|
||||
* Initializes a new ClassMetadata instance that will hold the object-relational mapping
|
||||
* metadata of the class with the given name.
|
||||
*
|
||||
* @param string $entityName The name of the entity class the new instance is used for.
|
||||
* @param ReflectionService $reflService The reflection service.
|
||||
*/
|
||||
public function initializeReflection($reflService)
|
||||
{
|
||||
$this->reflClass = $reflService->getClass($this->name);
|
||||
$this->namespace = $reflService->getClassNamespace($this->name);
|
||||
$this->table['name'] = $this->namingStrategy->classToTableName($reflService->getClassShortName($this->name));
|
||||
$this->table['name'] = $this->namingStrategy->classToTableName($this->name);
|
||||
|
||||
if ($this->reflClass) {
|
||||
$this->name = $this->rootEntityName = $this->reflClass->getName();
|
||||
|
@ -595,4 +595,50 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "The target-entity Doctrine\Tests\Models\CMS\UnknownClass cannot be found in 'Doctrine\Tests\Models\CMS\CmsUser#address'.");
|
||||
$cm->validateAssocations();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-984
|
||||
* @group DDC-559
|
||||
* @group DDC-1575
|
||||
*/
|
||||
public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategy()
|
||||
{
|
||||
$namingStrategy = new MyNamespacedNamingStrategy();
|
||||
$addressMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy);
|
||||
$articleMetadata = new ClassMetadata('DoctrineGlobal_Article', $namingStrategy);
|
||||
$routingMetadata = new ClassMetadata('Doctrine\Tests\Models\Routing\RoutingLeg',$namingStrategy);
|
||||
|
||||
$addressMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
|
||||
$articleMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
|
||||
$routingMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
|
||||
|
||||
$addressMetadata->mapManyToMany(array(
|
||||
'fieldName' => 'user',
|
||||
'targetEntity' => 'CmsUser'
|
||||
));
|
||||
|
||||
$articleMetadata->mapManyToMany(array(
|
||||
'fieldName' => 'author',
|
||||
'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser'
|
||||
));
|
||||
|
||||
$this->assertEquals('routing_routingleg', $routingMetadata->table['name']);
|
||||
$this->assertEquals('cms_cmsaddress_cms_cmsuser', $addressMetadata->associationMappings['user']['joinTable']['name']);
|
||||
$this->assertEquals('doctrineglobal_article_cms_cmsuser', $articleMetadata->associationMappings['author']['joinTable']['name']);
|
||||
}
|
||||
}
|
||||
|
||||
class MyNamespacedNamingStrategy extends \Doctrine\ORM\Mapping\DefaultNamingStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function classToTableName($className)
|
||||
{
|
||||
if (strpos($className, '\\') !== false) {
|
||||
$className = str_replace('\\', '_', str_replace('Doctrine\Tests\Models\\', '', $className));
|
||||
}
|
||||
|
||||
return strtolower($className);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user