From debc6e4993234bb4fd98a705202a5721ddab948a Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 11 Jun 2012 14:21:07 -0300 Subject: [PATCH] change QuoteStrategy#getJoinColumnName to use join column --- .gitignore | 5 +++ .../ORM/Mapping/DefaultQuoteStrategy.php | 38 ++++--------------- lib/Doctrine/ORM/Mapping/QuoteStrategy.php | 8 ++-- .../ORM/Persisters/BasicEntityPersister.php | 16 ++++---- lib/Doctrine/ORM/Tools/SchemaTool.php | 11 ++---- .../Tests/ORM/Mapping/QuoteStrategyTest.php | 2 +- 6 files changed, 30 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index a91841777..265037d31 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,8 @@ lib/Doctrine/DBAL /.settings/ .buildpath .project +/.AppleDouble/ +/bin/.AppleDouble/ +/lib/.AppleDouble/ +/tests/.AppleDouble/ +/tools/.AppleDouble/ \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index 9ab835a31..076d98b2a 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -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']; } /** diff --git a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php index c994b5139..9e16999d8 100644 --- a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php @@ -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. diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 400d0f77e..021c8692e 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -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) { diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 70e5d3224..1ef28f1cb 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -36,7 +36,6 @@ use Doctrine\ORM\ORMException, * * @link www.doctrine-project.org * @since 2.0 - * @version $Revision$ * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel @@ -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; diff --git a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php index 4e832060b..b56222e2b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php @@ -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');