Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #705 from FabioBatSilva/DDC-2519

[DDC-2519] Partial association identifier
  • Loading branch information...
commit 2ce72f38a2a13c665cd7e2ee5d79eb82d2c8003b 2 parents eaf8fd3 + 1cff8b4
@guilhermeblanco guilhermeblanco authored
View
6 lib/Doctrine/ORM/Query/Parser.php
@@ -670,6 +670,12 @@ private function processDeferredPartialObjectExpressions()
continue;
}
+ if (isset($class->associationMappings[$field]) &&
+ $class->associationMappings[$field]['isOwningSide'] &&
+ $class->associationMappings[$field]['type'] & ClassMetadata::TO_ONE) {
+ continue;
+ }
+
$this->semanticalError(
"There is no mapped field named '$field' on class " . $class->name . ".", $deferredItem['token']
);
View
85 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2519Test.php
@@ -0,0 +1,85 @@
+<?php
+
+namespace Doctrine\Tests\ORM\Functional\Ticket;
+
+use Doctrine\Tests\Models\Legacy\LegacyUser;
+use Doctrine\Tests\Models\Legacy\LegacyUserReference;
+
+/**
+ * @group DDC-2519
+ */
+class DDC2519Test extends \Doctrine\Tests\OrmFunctionalTestCase
+{
+ private $userId;
+
+ public function setUp()
+ {
+ $this->useModelSet('legacy');
+ parent::setUp();
+
+ $this->loadFixture();
+ }
+
+ /**
+ * @group DDC-2519
+ */
+ public function testIssue()
+ {
+ $dql = 'SELECT PARTIAL l.{_source, _target} FROM Doctrine\Tests\Models\Legacy\LegacyUserReference l';
+ $result = $this->_em->createQuery($dql)->getResult();
+
+ $this->assertCount(2, $result);
+ $this->assertInstanceOf('Doctrine\Tests\Models\Legacy\LegacyUserReference', $result[0]);
+ $this->assertInstanceOf('Doctrine\Tests\Models\Legacy\LegacyUserReference', $result[1]);
+
+ $this->assertInstanceOf('Doctrine\Tests\Models\Legacy\LegacyUser', $result[0]->source());
+ $this->assertInstanceOf('Doctrine\Tests\Models\Legacy\LegacyUser', $result[0]->target());
+ $this->assertInstanceOf('Doctrine\Tests\Models\Legacy\LegacyUser', $result[1]->source());
+ $this->assertInstanceOf('Doctrine\Tests\Models\Legacy\LegacyUser', $result[1]->target());
+
+ $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $result[0]->source());
+ $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $result[0]->target());
+ $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $result[1]->source());
+ $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $result[1]->target());
+
+ $this->assertFalse($result[0]->target()->__isInitialized());
+ $this->assertFalse($result[0]->source()->__isInitialized());
+ $this->assertFalse($result[1]->target()->__isInitialized());
+ $this->assertFalse($result[1]->source()->__isInitialized());
+
+ $this->assertNotNull($result[0]->source()->getId());
+ $this->assertNotNull($result[0]->target()->getId());
+ $this->assertNotNull($result[1]->source()->getId());
+ $this->assertNotNull($result[1]->target()->getId());
+ }
+
+ public function loadFixture()
+ {
+ $user1 = new LegacyUser();
+ $user1->_username = 'FabioBatSilva';
+ $user1->_name = 'Fabio B. Silva';
+ $user1->_status = 'active';
+
+ $user2 = new LegacyUser();
+ $user2->_username = 'doctrinebot';
+ $user2->_name = 'Doctrine Bot';
+ $user2->_status = 'active';
+
+ $user3 = new LegacyUser();
+ $user3->_username = 'test';
+ $user3->_name = 'Tester';
+ $user3->_status = 'active';
+
+ $this->_em->persist($user1);
+ $this->_em->persist($user2);
+ $this->_em->persist($user3);
+
+ $this->_em->flush();
+
+ $this->_em->persist(new LegacyUserReference($user1, $user2, 'foo'));
+ $this->_em->persist(new LegacyUserReference($user1, $user3, 'bar'));
+
+ $this->_em->flush();
+ $this->_em->clear();
+ }
+}
View
16 tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
@@ -1293,6 +1293,22 @@ public function testIdentityFunctionWithCompositePrimaryKey()
}
/**
+ * @group DDC-2519
+ */
+ public function testPartialWithAssociationIdentifier()
+ {
+ $this->assertSqlGeneration(
+ "SELECT PARTIAL l.{_source, _target} FROM Doctrine\Tests\Models\Legacy\LegacyUserReference l",
+ 'SELECT l0_.iUserIdSource AS iUserIdSource0, l0_.iUserIdTarget AS iUserIdTarget1 FROM legacy_users_reference l0_'
+ );
+
+ $this->assertSqlGeneration(
+ "SELECT PARTIAL l.{_description, _source, _target} FROM Doctrine\Tests\Models\Legacy\LegacyUserReference l",
+ 'SELECT l0_.description AS description0, l0_.iUserIdSource AS iUserIdSource1, l0_.iUserIdTarget AS iUserIdTarget2 FROM legacy_users_reference l0_'
+ );
+ }
+
+ /**
* @group DDC-1339
*/
public function testIdentityFunctionInSelectClause()
Please sign in to comment.
Something went wrong with that request. Please try again.