Merge branch 'hotfix/#1252-include-class-name-when-calling-naming-strategy-join-column-name'
Close #1252
This commit is contained in:
commit
84562bca82
@ -78,7 +78,7 @@ a "naming standard" for database tables and columns.
|
||||
* @param string $propertyName A property
|
||||
* @return string A join column name
|
||||
*/
|
||||
function joinColumnName($propertyName);
|
||||
function joinColumnName($propertyName, $className = null);
|
||||
|
||||
/**
|
||||
* Return a join table name
|
||||
@ -124,7 +124,7 @@ You need to implements NamingStrategy first. Following is an example
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
public function joinColumnName($propertyName)
|
||||
public function joinColumnName($propertyName, $className = null)
|
||||
{
|
||||
return $propertyName . '_' . $this->referenceColumnName();
|
||||
}
|
||||
|
@ -1553,7 +1553,7 @@ class ClassMetadataInfo implements ClassMetadata
|
||||
if ( ! isset($mapping['joinColumns']) || ! $mapping['joinColumns']) {
|
||||
// Apply default join column
|
||||
$mapping['joinColumns'] = array(array(
|
||||
'name' => $this->namingStrategy->joinColumnName($mapping['fieldName']),
|
||||
'name' => $this->namingStrategy->joinColumnName($mapping['fieldName'], $this->name),
|
||||
'referencedColumnName' => $this->namingStrategy->referenceColumnName()
|
||||
));
|
||||
}
|
||||
@ -1571,7 +1571,7 @@ class ClassMetadataInfo implements ClassMetadata
|
||||
}
|
||||
|
||||
if (empty($joinColumn['name'])) {
|
||||
$joinColumn['name'] = $this->namingStrategy->joinColumnName($mapping['fieldName']);
|
||||
$joinColumn['name'] = $this->namingStrategy->joinColumnName($mapping['fieldName'], $this->name);
|
||||
}
|
||||
|
||||
if (empty($joinColumn['referencedColumnName'])) {
|
||||
|
@ -69,7 +69,7 @@ class DefaultNamingStrategy implements NamingStrategy
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function joinColumnName($propertyName)
|
||||
public function joinColumnName($propertyName, $className = null)
|
||||
{
|
||||
return $propertyName . '_' . $this->referenceColumnName();
|
||||
}
|
||||
|
@ -70,10 +70,12 @@ interface NamingStrategy
|
||||
* Returns a join column name for a property.
|
||||
*
|
||||
* @param string $propertyName A property name.
|
||||
* @param string|null $className The fully-qualified class name.
|
||||
* This parameter is omitted from the signature due to BC
|
||||
*
|
||||
* @return string A join column name.
|
||||
*/
|
||||
function joinColumnName($propertyName);
|
||||
function joinColumnName($propertyName/*, $className = null*/);
|
||||
|
||||
/**
|
||||
* Returns a join table name.
|
||||
|
@ -106,7 +106,7 @@ class UnderscoreNamingStrategy implements NamingStrategy
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function joinColumnName($propertyName)
|
||||
public function joinColumnName($propertyName, $className = null)
|
||||
{
|
||||
return $this->underscore($propertyName) . '_' . $this->referenceColumnName();
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Tests\ORM\Mapping\NamingStrategy;
|
||||
|
||||
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
|
||||
|
||||
/**
|
||||
* Stub naming strategy to verify `joinColumnName` proper behavior
|
||||
*/
|
||||
class JoinColumnClassNamingStrategy extends DefaultNamingStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function joinColumnName($propertyName, $className = null)
|
||||
{
|
||||
return strtolower($this->classToTableName($className))
|
||||
. '_' . $propertyName
|
||||
. '_' . $this->referenceColumnName();
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Mapping;
|
||||
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
|
||||
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
|
||||
use Doctrine\ORM\Mapping\NamingStrategy;
|
||||
use Doctrine\Tests\ORM\Mapping\NamingStrategy\JoinColumnClassNamingStrategy;
|
||||
|
||||
/**
|
||||
* @group DDC-559
|
||||
@ -162,20 +163,15 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
return array(
|
||||
// DefaultNamingStrategy
|
||||
array(self::defaultNaming(), 'someColumn_id',
|
||||
'someColumn', null,
|
||||
),
|
||||
array(self::defaultNaming(), 'some_column_id',
|
||||
'some_column', null,
|
||||
),
|
||||
array(self::defaultNaming(), 'someColumn_id', 'someColumn', null),
|
||||
array(self::defaultNaming(), 'some_column_id', 'some_column', null),
|
||||
|
||||
// UnderscoreNamingStrategy
|
||||
array(self::underscoreNamingLower(), 'some_column_id',
|
||||
'someColumn', null,
|
||||
),
|
||||
array(self::underscoreNamingUpper(), 'SOME_COLUMN_ID',
|
||||
'someColumn', null,
|
||||
),
|
||||
array(self::underscoreNamingLower(), 'some_column_id', 'someColumn', null),
|
||||
array(self::underscoreNamingUpper(), 'SOME_COLUMN_ID', 'someColumn', null),
|
||||
// JoinColumnClassNamingStrategy
|
||||
array(new JoinColumnClassNamingStrategy(), 'classname_someColumn_id', 'someColumn', 'Some\ClassName'),
|
||||
array(new JoinColumnClassNamingStrategy(), 'classname_some_column_id', 'some_column', 'ClassName'),
|
||||
);
|
||||
}
|
||||
|
||||
@ -186,9 +182,9 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
|
||||
* @param string $expected
|
||||
* @param string $propertyName
|
||||
*/
|
||||
public function testJoinColumnName(NamingStrategy $strategy, $expected, $propertyName)
|
||||
public function testJoinColumnName(NamingStrategy $strategy, $expected, $propertyName, $className = null)
|
||||
{
|
||||
$this->assertEquals($expected, $strategy->joinColumnName($propertyName));
|
||||
$this->assertEquals($expected, $strategy->joinColumnName($propertyName, $className));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user