From f4c0fd17445928862481618b3d4ead61d039567c Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Tue, 27 Nov 2012 14:36:56 -0500 Subject: [PATCH] Added support to subselects in update item. --- lib/Doctrine/ORM/Query/Parser.php | 2 +- .../Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index d057ba754..bdf179d0f 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1488,7 +1488,7 @@ class Parser return new AST\InputParameter($this->lexer->token['value']); } - return $this->SimpleArithmeticExpression(); + return $this->ArithmeticExpression(); } /** diff --git a/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php index a65efe079..7545c291e 100644 --- a/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php @@ -202,4 +202,12 @@ class UpdateSqlGenerationTest extends \Doctrine\Tests\OrmTestCase 'UPDATE customtype_parents SET customInteger = 1 WHERE id = 1' ); } + + public function testUpdateWithSubselectAsNewValue() + { + $this->assertSqlGeneration( + "UPDATE Doctrine\Tests\Models\Company\CompanyFixContract fc SET fc.fixPrice = (SELECT ce2.salary FROM Doctrine\Tests\Models\Company\CompanyEmployee ce2 WHERE ce2.id = 2) WHERE fc.id = 1", + "UPDATE company_contracts SET fixPrice = (SELECT c0_.salary FROM company_employees c0_ INNER JOIN company_persons c1_ ON c0_.id = c1_.id LEFT JOIN company_managers c2_ ON c0_.id = c2_.id WHERE c1_.id = 2) WHERE (id = 1) AND discr IN ('fix')" + ); + } }