Permalink
Browse files

Merge pull request #391 from FabioBatSilva/ns-class

Give FQCN to NamingStrategy#propertyToColumnName
  • Loading branch information...
2 parents 72ce9a7 + 1369e3d commit f8a582d454507270f82b9083aa5c8dd22021f7d9 @guilhermeblanco guilhermeblanco committed Aug 12, 2012
@@ -1188,7 +1188,7 @@ protected function _validateAndCompleteFieldMapping(array &$mapping)
// 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 @@ protected function _validateAndCompleteManyToManyMapping(array $mapping)
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']),
@@ -45,7 +45,7 @@ public function classToTableName($className)
/**
* {@inheritdoc}
*/
- public function propertyToColumnName($propertyName)
+ public function propertyToColumnName($propertyName, $className = null)
{
return $propertyName;
}
@@ -42,9 +42,10 @@ function classToTableName($className);
* 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
@@ -80,7 +80,7 @@ public function classToTableName($className)
/**
* {@inheritdoc}
*/
- public function propertyToColumnName($propertyName)
+ public function propertyToColumnName($propertyName, $className = null)
{
return $this->underscore($propertyName);
}
@@ -923,6 +923,26 @@ public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategy()
}
/**
+ * @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
*/
public function testInvalidCascade()
@@ -993,3 +1013,14 @@ public function classToTableName($className)
return strtolower($className);
}
}
+
+class MyPrefixNamingStrategy extends \Doctrine\ORM\Mapping\DefaultNamingStrategy
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function propertyToColumnName($propertyName, $className = null)
+ {
+ return strtolower($this->classToTableName($className)) . '_' . $propertyName;
+ }
+}

0 comments on commit f8a582d

Please sign in to comment.