diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 67ee0729d..a82d9d82f 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -670,6 +670,12 @@ class Parser 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'] ); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2519Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2519Test.php new file mode 100644 index 000000000..d6ea115b5 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2519Test.php @@ -0,0 +1,85 @@ +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(); + } +} diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 785e25850..dbb303323 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1292,6 +1292,22 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); } + /** + * @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 */