From 192da148428e62cea53fa2b918daf14f85cd7286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Thu, 9 Apr 2015 01:42:46 +0200 Subject: [PATCH 1/2] Failing test case for broken paginator case --- .../LimitSubqueryOutputWalkerTest.php | 19 +++++++++++++++++ .../Tools/Pagination/PaginationTestCase.php | 21 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php index 205be7d1f..f20a0e481 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php @@ -350,5 +350,24 @@ ORDER BY b.id DESC' $query->getSQL() ); } + + /** + * This tests ordering by property that has the 'declared' field. + */ + public function testLimitSubqueryOrderByFieldFromMappedSuperclass() + { + $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform()); + + // now use the third one in query + $query = $this->entityManager->createQuery( + 'SELECT b FROM Doctrine\Tests\ORM\Tools\Pagination\Banner b ORDER BY b.id DESC' + ); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + + $this->assertEquals( + 'SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, b0_.name AS name_1 FROM Banner b0_) dctrn_result ORDER BY id_0 DESC', + $query->getSQL() + ); + } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php index f1553c13c..fe8ee0f82 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php @@ -168,4 +168,23 @@ class Avatar public $image_width; /** @Column(type="string", length=255) */ public $image_alt_desc; -} \ No newline at end of file +} + +/** @MappedSuperclass */ +abstract class Identified +{ + /** @Id @Column(type="integer") @GeneratedValue */ + private $id; + + public function getId() + { + return $this->id; + } +} + +/** @Entity */ +class Banner extends Identified +{ + /** @Column(type="string") */ + public $name; +} From e501137d1afff2c08963828b61b0b8b6668edd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Thu, 9 Apr 2015 01:43:05 +0200 Subject: [PATCH 2/2] LimitSubqueryOutputWalker: fix aliasing of property in OrderBy from MappedSuperclass --- .../ORM/Tools/Pagination/LimitSubqueryOutputWalker.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php index 22d0628ba..fc431227f 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php @@ -438,7 +438,9 @@ class LimitSubqueryOutputWalker extends SqlWalker // Field was declared in a parent class, so we need to get the proper SQL table alias // for the joined parent table. $otherClassMetadata = $this->em->getClassMetadata($fieldMapping['declared']); - $sqlTableAliasForFieldAlias = $this->getSQLTableAlias($otherClassMetadata->getTableName(), $dqlAliasForFieldAlias); + if (!$otherClassMetadata->isMappedSuperclass) { + $sqlTableAliasForFieldAlias = $this->getSQLTableAlias($otherClassMetadata->getTableName(), $dqlAliasForFieldAlias); + } } // Compose search/replace patterns