diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index d8894923eb1..2edf754e94c 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1180,7 +1180,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); } else { if ($mapping['columnName'][0] == '`') { $mapping['columnName'] = trim($mapping['columnName'], '`'); @@ -1357,8 +1357,8 @@ protected function _validateAndCompleteOneToOneMapping(array $mapping) if ( ! isset($mapping['joinColumns']) || ! $mapping['joinColumns']) { // Apply default join column $mapping['joinColumns'] = array(array( - 'name' => $this->namingStrategy->joinColumnName($mapping['fieldName']), - 'referencedColumnName' => $this->namingStrategy->referenceColumnName() + 'name' => $this->namingStrategy->joinColumnName($mapping['fieldName'], $this->name), + 'referencedColumnName' => $this->namingStrategy->referenceColumnName($this->name) )); } @@ -1374,10 +1374,10 @@ protected function _validateAndCompleteOneToOneMapping(array $mapping) } } if (empty($joinColumn['name'])) { - $joinColumn['name'] = $this->namingStrategy->joinColumnName($mapping['fieldName']); + $joinColumn['name'] = $this->namingStrategy->joinColumnName($mapping['fieldName'], $this->name); } if (empty($joinColumn['referencedColumnName'])) { - $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName(); + $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName($this->name); } $mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName']; $mapping['joinColumnFieldNames'][$joinColumn['name']] = isset($joinColumn['fieldName']) @@ -1440,27 +1440,27 @@ protected function _validateAndCompleteManyToManyMapping(array $mapping) if ($mapping['isOwningSide']) { // owning side MUST have a join table 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'], $this->name); } if ( ! isset($mapping['joinTable']['joinColumns'])) { $mapping['joinTable']['joinColumns'] = array(array( - 'name' => $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity']), - 'referencedColumnName' => $this->namingStrategy->referenceColumnName(), + 'name' => $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity'], $this->name), + 'referencedColumnName' => $this->namingStrategy->referenceColumnName($this->name), 'onDelete' => 'CASCADE')); } if ( ! isset($mapping['joinTable']['inverseJoinColumns'])) { $mapping['joinTable']['inverseJoinColumns'] = array(array( - 'name' => $this->namingStrategy->joinKeyColumnName($mapping['targetEntity']), - 'referencedColumnName' => $this->namingStrategy->referenceColumnName(), + 'name' => $this->namingStrategy->joinKeyColumnName($mapping['targetEntity'], $this->name), + 'referencedColumnName' => $this->namingStrategy->referenceColumnName($this->name), 'onDelete' => 'CASCADE')); } foreach ($mapping['joinTable']['joinColumns'] as &$joinColumn) { if (empty($joinColumn['name'])) { - $joinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity'], $joinColumn['referencedColumnName']); + $joinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity'], $joinColumn['referencedColumnName'], $this->name); } if (empty($joinColumn['referencedColumnName'])) { - $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName(); + $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName($this->name); } if (isset($joinColumn['onDelete']) && strtolower($joinColumn['onDelete']) == 'cascade') { $mapping['isOnDeleteCascade'] = true; @@ -1471,10 +1471,10 @@ protected function _validateAndCompleteManyToManyMapping(array $mapping) foreach ($mapping['joinTable']['inverseJoinColumns'] as &$inverseJoinColumn) { if (empty($inverseJoinColumn['name'])) { - $inverseJoinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['targetEntity'], $inverseJoinColumn['referencedColumnName']); + $inverseJoinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['targetEntity'], $inverseJoinColumn['referencedColumnName'], $this->name); } if (empty($inverseJoinColumn['referencedColumnName'])) { - $inverseJoinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName(); + $inverseJoinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName($this->name); } if (isset($inverseJoinColumn['onDelete']) && strtolower($inverseJoinColumn['onDelete']) == 'cascade') { $mapping['isOnDeleteCascade'] = true; diff --git a/lib/Doctrine/ORM/Mapping/DefaultNamingStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultNamingStrategy.php index 5bfe3157737..8d0bfb656e9 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultNamingStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultNamingStrategy.php @@ -30,6 +30,7 @@ */ class DefaultNamingStrategy implements NamingStrategy { + /** * {@inheritdoc} */ @@ -45,7 +46,7 @@ public function classToTableName($className) /** * {@inheritdoc} */ - public function propertyToColumnName($propertyName) + public function propertyToColumnName($propertyName, $className = null) { return $propertyName; } @@ -53,7 +54,7 @@ public function propertyToColumnName($propertyName) /** * {@inheritdoc} */ - public function referenceColumnName() + public function referenceColumnName($className = null) { return 'id'; } @@ -61,15 +62,15 @@ public function referenceColumnName() /** * {@inheritdoc} */ - public function joinColumnName($propertyName) + public function joinColumnName($propertyName, $className = null) { - return $propertyName . '_' . $this->referenceColumnName(); + return $propertyName . '_' . $this->referenceColumnName($className); } /** * {@inheritdoc} */ - public function joinTableName($sourceEntity, $targetEntity, $propertyName = null) + public function joinTableName($sourceEntity, $targetEntity, $propertyName = null, $className = null) { return strtolower($this->classToTableName($sourceEntity) . '_' . $this->classToTableName($targetEntity)); @@ -78,9 +79,9 @@ public function joinTableName($sourceEntity, $targetEntity, $propertyName = null /** * {@inheritdoc} */ - public function joinKeyColumnName($entityName, $referencedColumnName = null) + public function joinKeyColumnName($entityName, $referencedColumnName = null, $className = null) { return strtolower($this->classToTableName($entityName) . '_' . - ($referencedColumnName ?: $this->referenceColumnName())); + ($referencedColumnName ?: $this->referenceColumnName($className))); } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/NamingStrategy.php b/lib/Doctrine/ORM/Mapping/NamingStrategy.php index 8a7cbb33555..b82abc11111 100644 --- a/lib/Doctrine/ORM/Mapping/NamingStrategy.php +++ b/lib/Doctrine/ORM/Mapping/NamingStrategy.php @@ -42,24 +42,27 @@ 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 - * + * + * @param string $className The fully-qualified class name * @return string A column name */ - function referenceColumnName(); + function referenceColumnName($className = null); /** * Return a join column name for a property * * @param string $propertyName A property + * @param string $className The fully-qualified class name * @return string A join column name */ - function joinColumnName($propertyName); + function joinColumnName($propertyName, $className = null); /** * Return a join table name @@ -67,16 +70,18 @@ function joinColumnName($propertyName); * @param string $sourceEntity The source entity * @param string $targetEntity The target entity * @param string $propertyName A property + * @param string $className The fully-qualified class name * @return string A join table name */ - function joinTableName($sourceEntity, $targetEntity, $propertyName = null); + function joinTableName($sourceEntity, $targetEntity, $propertyName = null, $className = null); /** * Return the foreign key column name for the given parameters * * @param string $entityName A entity * @param string $referencedColumnName A property + * @param string $className The fully-qualified class name * @return string A join column name */ - function joinKeyColumnName($entityName, $referencedColumnName = null); + function joinKeyColumnName($entityName, $referencedColumnName = null, $className = null); } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php b/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php index 44969d3d308..bcb1d073f81 100644 --- a/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php +++ b/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php @@ -35,7 +35,7 @@ class UnderscoreNamingStrategy implements NamingStrategy * @var integer */ private $case; - + /** * Underscore naming strategy construct * @@ -80,7 +80,7 @@ public function classToTableName($className) /** * {@inheritdoc} */ - public function propertyToColumnName($propertyName) + public function propertyToColumnName($propertyName, $className = null) { return $this->underscore($propertyName); } @@ -88,7 +88,7 @@ public function propertyToColumnName($propertyName) /** * {@inheritdoc} */ - public function referenceColumnName() + public function referenceColumnName($className = null) { return $this->case === CASE_UPPER ? 'ID' : 'id'; } @@ -96,7 +96,7 @@ public function referenceColumnName() /** * {@inheritdoc} */ - public function joinColumnName($propertyName) + public function joinColumnName($propertyName, $className = null) { return $this->underscore($propertyName) . '_' . $this->referenceColumnName(); } @@ -104,7 +104,7 @@ public function joinColumnName($propertyName) /** * {@inheritdoc} */ - public function joinTableName($sourceEntity, $targetEntity, $propertyName = null) + public function joinTableName($sourceEntity, $targetEntity, $propertyName = null, $className = null) { return $this->classToTableName($sourceEntity) . '_' . $this->classToTableName($targetEntity); } @@ -112,7 +112,7 @@ public function joinTableName($sourceEntity, $targetEntity, $propertyName = null /** * {@inheritdoc} */ - public function joinKeyColumnName($entityName, $referencedColumnName = null) + public function joinKeyColumnName($entityName, $referencedColumnName = null, $className = null) { return $this->classToTableName($entityName) . '_' . ($referencedColumnName ?: $this->referenceColumnName());