Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04254a8

Browse files
Merge pull request doctrine#1512 from neoglez/2.5
Backport of "LimitSubqueryOutputWalker: fix aliasing of property in OrderBy from MappedSuperclass"
2 parents 1d213e6 + ef73249 commit 04254a8

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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

tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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
*/

tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)