change QuoteStrategy#getJoinColumnName to use join column
This commit is contained in:
parent
46ec26e745
commit
debc6e4993
5
.gitignore
vendored
5
.gitignore
vendored
@ -9,3 +9,8 @@ lib/Doctrine/DBAL
|
||||
/.settings/
|
||||
.buildpath
|
||||
.project
|
||||
/.AppleDouble/
|
||||
/bin/.AppleDouble/
|
||||
/lib/.AppleDouble/
|
||||
/tests/.AppleDouble/
|
||||
/tools/.AppleDouble/
|
@ -62,43 +62,21 @@ class DefaultQuoteStrategy extends QuoteStrategy
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getJoinColumnName($columnName, array $association, ClassMetadata $class)
|
||||
public function getJoinColumnName(array $joinColumn, ClassMetadata $class)
|
||||
{
|
||||
if( ! isset($association['joinColumns'])) {
|
||||
return $columnName;
|
||||
}
|
||||
|
||||
foreach ($association['joinColumns'] as $joinColumn) {
|
||||
if($joinColumn['name'] === $columnName) {
|
||||
if (isset($joinColumn['quoted'])) {
|
||||
return $this->platform->quoteIdentifier($columnName);
|
||||
}
|
||||
return $columnName;
|
||||
}
|
||||
}
|
||||
|
||||
return $columnName;
|
||||
return isset($joinColumn['quoted'])
|
||||
? $this->platform->quoteIdentifier($joinColumn['name'])
|
||||
: $joinColumn['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getReferencedJoinColumnName($columnName, array $association, ClassMetadata $class)
|
||||
public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $class)
|
||||
{
|
||||
if( ! isset($association['joinColumns'])) {
|
||||
return $columnName;
|
||||
}
|
||||
|
||||
foreach ($association['joinColumns'] as $joinColumn) {
|
||||
if($joinColumn['referencedColumnName'] === $columnName) {
|
||||
if (isset($joinColumn['quoted'])) {
|
||||
return $this->platform->quoteIdentifier($columnName);
|
||||
}
|
||||
return $columnName;
|
||||
}
|
||||
}
|
||||
|
||||
return $columnName;
|
||||
return isset($joinColumn['quoted'])
|
||||
? $this->platform->quoteIdentifier($joinColumn['referencedColumnName'])
|
||||
: $joinColumn['referencedColumnName'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,20 +81,20 @@ abstract class QuoteStrategy
|
||||
/**
|
||||
* Gets the (possibly quoted) join column name.
|
||||
*
|
||||
* @param array $association
|
||||
* @param array $joinColumn
|
||||
* @param ClassMetadata $class
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getJoinColumnName($columnName, array $association, ClassMetadata $class);
|
||||
abstract public function getJoinColumnName(array $joinColumn, ClassMetadata $class);
|
||||
|
||||
/**
|
||||
* Gets the (possibly quoted) join column name.
|
||||
*
|
||||
* @param array $association
|
||||
* @param array $joinColumn
|
||||
* @param ClassMetadata $class
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getReferencedJoinColumnName($columnName, array $association, ClassMetadata $class);
|
||||
abstract public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $class);
|
||||
|
||||
/**
|
||||
* Gets the (possibly quoted) identifier column names for safe use in an SQL statement.
|
||||
|
@ -1077,13 +1077,14 @@ class BasicEntityPersister
|
||||
$columnList = '';
|
||||
|
||||
if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) {
|
||||
foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) {
|
||||
foreach ($assoc['joinColumns'] as $joinColumn) {
|
||||
|
||||
if ($columnList) $columnList .= ', ';
|
||||
|
||||
$quotedColumn = $this->quoteStrategy->getJoinColumnName($srcColumn, $assoc, $this->_class);
|
||||
$resultColumnName = $this->getSQLColumnAlias($srcColumn);
|
||||
$columnList .= $this->_getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) )
|
||||
. '.' . $quotedColumn . ' AS ' . $resultColumnName;
|
||||
$quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class);
|
||||
$resultColumnName = $this->getSQLColumnAlias($joinColumn['name']);
|
||||
$columnList .= $this->_getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) )
|
||||
. '.' . $quotedColumn . ' AS ' . $resultColumnName;
|
||||
$this->_rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, isset($assoc['id']) && $assoc['id'] === true);
|
||||
}
|
||||
}
|
||||
@ -1189,10 +1190,9 @@ class BasicEntityPersister
|
||||
|
||||
if (isset($this->_class->associationMappings[$name])) {
|
||||
$assoc = $this->_class->associationMappings[$name];
|
||||
|
||||
if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) {
|
||||
foreach ($assoc['targetToSourceKeyColumns'] as $sourceCol) {
|
||||
$columns[] = $this->quoteStrategy->getJoinColumnName($sourceCol, $assoc, $this->_class);
|
||||
foreach ($assoc['joinColumns'] as $joinColumn) {
|
||||
$columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class);
|
||||
}
|
||||
}
|
||||
} else if ($this->_class->generatorType != ClassMetadata::GENERATOR_TYPE_IDENTITY || $this->_class->identifier[0] != $name) {
|
||||
|
@ -36,7 +36,6 @@ use Doctrine\ORM\ORMException,
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
@ -222,7 +221,7 @@ class SchemaTool
|
||||
/* @var $assoc \Doctrine\ORM\Mapping\OneToOne */
|
||||
$assoc = $class->associationMappings[$identifierField];
|
||||
foreach ($assoc['joinColumns'] as $joinColumn) {
|
||||
$pkColumns[] = $this->quoteStrategy->getJoinColumnName($joinColumn['name'], $assoc, $class);
|
||||
$pkColumns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -513,10 +512,8 @@ class SchemaTool
|
||||
$foreignTableName = $this->quoteStrategy->getTableName($class);
|
||||
|
||||
foreach ($joinColumns as $joinColumn) {
|
||||
$columnName = $joinColumn['name'];
|
||||
$referencedColumnName = $joinColumn['referencedColumnName'];
|
||||
|
||||
list($definingClass, $referencedFieldName) = $this->getDefiningClass($class, $referencedColumnName);
|
||||
list($definingClass, $referencedFieldName) = $this->getDefiningClass($class, $joinColumn['referencedColumnName']);
|
||||
|
||||
if (!$definingClass) {
|
||||
throw new \Doctrine\ORM\ORMException(
|
||||
@ -525,8 +522,8 @@ class SchemaTool
|
||||
);
|
||||
}
|
||||
|
||||
$quotedColumnName = $this->quoteStrategy->getJoinColumnName($columnName, $mapping, $class);
|
||||
$quotedRefColumnName = $this->quoteStrategy->getReferencedJoinColumnName($referencedColumnName, $mapping, $class);
|
||||
$quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class);
|
||||
$quotedRefColumnName = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $class);
|
||||
|
||||
$primaryKeyColumns[] = $quotedColumnName;
|
||||
$localColumns[] = $quotedColumnName;
|
||||
|
@ -120,7 +120,7 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->assertEquals('COLUMNNAME3', $this->strategy->getColumnAlias('COLUMN-NAME-', $i++));
|
||||
}
|
||||
|
||||
public function testQuoteJoinColumnNames()
|
||||
public function testQuoteIdentifierJoinColumns()
|
||||
{
|
||||
$cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user