Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'], '`');
Expand Down Expand Up @@ -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)
));
}

Expand All @@ -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'])
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions lib/Doctrine/ORM/Mapping/DefaultNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/
class DefaultNamingStrategy implements NamingStrategy
{

/**
* {@inheritdoc}
*/
Expand All @@ -45,31 +46,31 @@ public function classToTableName($className)
/**
* {@inheritdoc}
*/
public function propertyToColumnName($propertyName)
public function propertyToColumnName($propertyName, $className = null)
{
return $propertyName;
}

/**
* {@inheritdoc}
*/
public function referenceColumnName()
public function referenceColumnName($className = null)
{
return 'id';
}

/**
* {@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));
Expand All @@ -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)));
}
}
17 changes: 11 additions & 6 deletions lib/Doctrine/ORM/Mapping/NamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,46 @@ 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
*
* @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);
}
12 changes: 6 additions & 6 deletions lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class UnderscoreNamingStrategy implements NamingStrategy
* @var integer
*/
private $case;

/**
* Underscore naming strategy construct
*
Expand Down Expand Up @@ -80,39 +80,39 @@ public function classToTableName($className)
/**
* {@inheritdoc}
*/
public function propertyToColumnName($propertyName)
public function propertyToColumnName($propertyName, $className = null)
{
return $this->underscore($propertyName);
}

/**
* {@inheritdoc}
*/
public function referenceColumnName()
public function referenceColumnName($className = null)
{
return $this->case === CASE_UPPER ? 'ID' : 'id';
}

/**
* {@inheritdoc}
*/
public function joinColumnName($propertyName)
public function joinColumnName($propertyName, $className = null)
{
return $this->underscore($propertyName) . '_' . $this->referenceColumnName();
}

/**
* {@inheritdoc}
*/
public function joinTableName($sourceEntity, $targetEntity, $propertyName = null)
public function joinTableName($sourceEntity, $targetEntity, $propertyName = null, $className = null)
{
return $this->classToTableName($sourceEntity) . '_' . $this->classToTableName($targetEntity);
}

/**
* {@inheritdoc}
*/
public function joinKeyColumnName($entityName, $referencedColumnName = null)
public function joinKeyColumnName($entityName, $referencedColumnName = null, $className = null)
{
return $this->classToTableName($entityName) . '_' .
($referencedColumnName ?: $this->referenceColumnName());
Expand Down