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