File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -438,7 +438,10 @@ private function rebuildOrderByClauseForOuterScope(OrderByClause $orderByClause)
438438 // Field was declared in a parent class, so we need to get the proper SQL table alias
439439 // for the joined parent table.
440440 $ otherClassMetadata = $ this ->em ->getClassMetadata ($ fieldMapping ['declared ' ]);
441- $ sqlTableAliasForFieldAlias = $ this ->getSQLTableAlias ($ otherClassMetadata ->getTableName (), $ dqlAliasForFieldAlias );
441+ if (!$ otherClassMetadata ->isMappedSuperclass ) {
442+ $ sqlTableAliasForFieldAlias = $ this ->getSQLTableAlias ($ otherClassMetadata ->getTableName (), $ dqlAliasForFieldAlias );
443+
444+ }
442445 }
443446
444447 // Compose search/replace patterns
Original file line number Diff line number Diff line change @@ -350,7 +350,26 @@ public function testLimitSubqueryWithOrderByAndSubSelectInWhereClausePgSql()
350350 $ query ->getSQL ()
351351 );
352352 }
353+
354+ /**
355+ * This tests ordering by property that has the 'declared' field.
356+ */
357+ public function testLimitSubqueryOrderByFieldFromMappedSuperclass ()
358+ {
359+ $ this ->entityManager ->getConnection ()->setDatabasePlatform (new MySqlPlatform ());
360+
361+ // now use the third one in query
362+ $ query = $ this ->entityManager ->createQuery (
363+ 'SELECT b FROM Doctrine\Tests\ORM\Tools\Pagination\Banner b ORDER BY b.id DESC '
364+ );
365+ $ query ->setHint (Query::HINT_CUSTOM_OUTPUT_WALKER , 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker ' );
353366
367+ $ this ->assertEquals (
368+ '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 ' ,
369+ $ query ->getSQL ()
370+ );
371+ }
372+
354373 /**
355374 * Tests order by on a subselect expression (mysql).
356375 */
Original file line number Diff line number Diff line change @@ -168,4 +168,22 @@ class Avatar
168168 public $ image_width ;
169169 /** @Column(type="string", length=255) */
170170 public $ image_alt_desc ;
171- }
171+ }
172+
173+ /** @MappedSuperclass */
174+ abstract class Identified
175+ {
176+ /** @Id @Column(type="integer") @GeneratedValue */
177+ private $ id ;
178+ public function getId ()
179+ {
180+ return $ this ->id ;
181+ }
182+ }
183+
184+ /** @Entity */
185+ class Banner extends Identified
186+ {
187+ /** @Column(type="string") */
188+ public $ name ;
189+ }
You can’t perform that action at this time.
0 commit comments