From 5ecca4f5e0817d0bc5769e20c8588529249cfae5 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Thu, 22 Apr 2010 11:32:01 -0300 Subject: [PATCH] [2.0][DDC-524] Fixed issue with UPDATE/DELETE statements generating wrong SQL when using Association Paths. --- lib/Doctrine/ORM/Query/SqlWalker.php | 8 ++++++-- .../Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index f624798fd..ece61bd50 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -478,8 +478,12 @@ class SqlWalker implements TreeWalker if (count($assoc->sourceToTargetKeyColumns) > 1) { throw QueryException::associationPathCompositeKeyNotSupported(); } - $sql .= $this->getSqlTableAlias($class->table['name'], $dqlAlias) . '.' - . reset($assoc->targetToSourceKeyColumns); + + if ($this->_useSqlTableAliases) { + $sql .= $this->getSqlTableAlias($class->table['name'], $dqlAlias) . '.'; + } + + $sql .= reset($assoc->targetToSourceKeyColumns); } else { // 2- Inverse side: NOT (YET?) SUPPORTED throw QueryException::associationPathInverseSideNotSupported(); diff --git a/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php index 969ee35ca..506dacb8b 100644 --- a/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php @@ -159,4 +159,12 @@ class UpdateSqlGenerationTest extends \Doctrine\Tests\OrmTestCase 'UPDATE cms_users SET status = ? WHERE id BETWEEN ? AND ?' ); } + + public function testSingleValuedAssociationFieldInWhere() + { + $this->assertSqlGeneration( + "UPDATE Doctrine\Tests\Models\CMS\CmsPhonenumber p SET p.phonenumber = 1234 WHERE p.user = ?1", + "UPDATE cms_phonenumbers SET phonenumber = 1234 WHERE user_id = ?" + ); + } }