1
0
mirror of synced 2024-12-13 14:56:01 +03:00

give FQCN to NamingStrategy#propertyToColumnName

This commit is contained in:
Fabio B. Silva 2012-07-05 23:46:08 +02:00 committed by fabio.silva
parent 619d29adb2
commit 50dac4096a
5 changed files with 36 additions and 4 deletions

View File

@ -1188,7 +1188,7 @@ class ClassMetadataInfo implements ClassMetadata
// Complete fieldName and columnName mapping
if ( ! isset($mapping['columnName'])) {
$mapping['columnName'] = $this->namingStrategy->propertyToColumnName($mapping['fieldName']);
$mapping['columnName'] = $this->namingStrategy->propertyToColumnName($mapping['fieldName'], $this->name);
}
if ($mapping['columnName'][0] === '`') {
@ -1465,6 +1465,7 @@ class ClassMetadataInfo implements ClassMetadata
if ( ! isset($mapping['joinTable']['name'])) {
$mapping['joinTable']['name'] = $this->namingStrategy->joinTableName($mapping['sourceEntity'], $mapping['targetEntity'], $mapping['fieldName']);
}
if ( ! isset($mapping['joinTable']['joinColumns'])) {
$mapping['joinTable']['joinColumns'] = array(array(
'name' => $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity']),

View File

@ -45,7 +45,7 @@ class DefaultNamingStrategy implements NamingStrategy
/**
* {@inheritdoc}
*/
public function propertyToColumnName($propertyName)
public function propertyToColumnName($propertyName, $className = null)
{
return $propertyName;
}

View File

@ -42,9 +42,10 @@ interface NamingStrategy
* Return a column name for a property
*
* @param string $propertyName A property
* @param string $className The fully-qualified class name
* @return string A column name
*/
function propertyToColumnName($propertyName);
function propertyToColumnName($propertyName, $className = null);
/**
* Return the default reference column name

View File

@ -80,7 +80,7 @@ class UnderscoreNamingStrategy implements NamingStrategy
/**
* {@inheritdoc}
*/
public function propertyToColumnName($propertyName)
public function propertyToColumnName($propertyName, $className = null)
{
return $this->underscore($propertyName);
}

View File

@ -922,6 +922,25 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('doctrineglobal_article_cms_cmsuser', $articleMetadata->associationMappings['author']['joinTable']['name']);
}
/**
* @group DDC-1575
*/
public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategyPropertyToColumnName()
{
$namingStrategy = new MyPrefixNamingStrategy();
$metadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy);
$metadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$metadata->mapField(array('fieldName'=>'country'));
$metadata->mapField(array('fieldName'=>'city'));
$this->assertEquals($metadata->fieldNames, array(
'cmsaddress_country' => 'country',
'cmsaddress_city' => 'city'
));
}
/**
* @group DDC-1746
*/
@ -993,3 +1012,14 @@ class MyNamespacedNamingStrategy extends \Doctrine\ORM\Mapping\DefaultNamingStra
return strtolower($className);
}
}
class MyPrefixNamingStrategy extends \Doctrine\ORM\Mapping\DefaultNamingStrategy
{
/**
* {@inheritdoc}
*/
public function propertyToColumnName($propertyName, $className = null)
{
return strtolower($this->classToTableName($className)) . '_' . $propertyName;
}
}