1
0
mirror of synced 2024-12-05 03:06:05 +03:00

Fix paginator when ordering by while selecting entities using joined table inheritance

This commit is contained in:
Bill Schaller 2015-03-30 12:16:50 -04:00 committed by Marco Pivetta
parent 09d28819b5
commit edcc0fc024
2 changed files with 28 additions and 0 deletions

View File

@ -412,14 +412,33 @@ class LimitSubqueryOutputWalker extends SqlWalker
// Generate search patterns for each field's path expression in the order by clause
foreach($this->_rsm->fieldMappings as $fieldAlias => $columnName) {
$dqlAliasForFieldAlias = $this->_rsm->columnOwnerMap[$fieldAlias];
$class = $dqlAliasToClassMap[$dqlAliasForFieldAlias];
// If the field is from a joined child table, we won't be ordering
// on it.
if (!isset($class->fieldMappings[$columnName])) {
continue;
}
// Get the proper column name as will appear in the select list
$columnName = $this->_quoteStrategy->getColumnName(
$columnName,
$dqlAliasToClassMap[$dqlAliasForFieldAlias],
$this->_em->getConnection()->getDatabasePlatform()
);
// Get the SQL table alias for the entity and field
$sqlTableAliasForFieldAlias = $dqlAliasToSqlTableAliasMap[$dqlAliasForFieldAlias];
$fieldMapping = $class->fieldMappings[$columnName];
if (isset($fieldMapping['declared']) && $fieldMapping['declared'] !== $class->name) {
// 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);
}
// Compose search/replace patterns
$searchPatterns[] = sprintf($fieldSearchPattern, $sqlTableAliasForFieldAlias, $columnName);
$replacements[] = $fieldAlias;
}

View File

@ -8,6 +8,7 @@ use Doctrine\Tests\Models\CMS\CmsEmail;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsGroup;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Doctrine\Tests\Models\Company\CompanyManager;
use Doctrine\Tests\Models\Pagination\Company;
use Doctrine\Tests\Models\Pagination\Department;
use Doctrine\Tests\Models\Pagination\Logo;
@ -725,6 +726,14 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->persist($user);
}
$manager = new CompanyManager();
$manager->setName('Roman B.');
$manager->setTitle('Foo');
$manager->setDepartment('IT');
$manager->setSalary(100000);
$this->_em->persist($manager);
$this->_em->flush();
}