1
0
mirror of synced 2024-12-13 22:56:04 +03:00

Merge pull request #391 from FabioBatSilva/ns-class

Give FQCN to NamingStrategy#propertyToColumnName
This commit is contained in:
Guilherme Blanco 2012-08-12 15:50:20 -07:00
commit f8a582d454
5 changed files with 37 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -922,6 +922,26 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('doctrineglobal_article_cms_cmsuser', $articleMetadata->associationMappings['author']['joinTable']['name']); $this->assertEquals('doctrineglobal_article_cms_cmsuser', $articleMetadata->associationMappings['author']['joinTable']['name']);
} }
/**
* @group DDC-984
* @group DDC-559
*/
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 * @group DDC-1746
*/ */
@ -993,3 +1013,14 @@ class MyNamespacedNamingStrategy extends \Doctrine\ORM\Mapping\DefaultNamingStra
return strtolower($className); return strtolower($className);
} }
} }
class MyPrefixNamingStrategy extends \Doctrine\ORM\Mapping\DefaultNamingStrategy
{
/**
* {@inheritdoc}
*/
public function propertyToColumnName($propertyName, $className = null)
{
return strtolower($this->classToTableName($className)) . '_' . $propertyName;
}
}