Fix paginator when ordering by while selecting entities using joined table inheritance
This commit is contained in:
parent
09d28819b5
commit
edcc0fc024
2 changed files with 28 additions and 0 deletions
|
@ -412,14 +412,33 @@ class LimitSubqueryOutputWalker extends SqlWalker
|
||||||
// Generate search patterns for each field's path expression in the order by clause
|
// Generate search patterns for each field's path expression in the order by clause
|
||||||
foreach($this->_rsm->fieldMappings as $fieldAlias => $columnName) {
|
foreach($this->_rsm->fieldMappings as $fieldAlias => $columnName) {
|
||||||
$dqlAliasForFieldAlias = $this->_rsm->columnOwnerMap[$fieldAlias];
|
$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 = $this->_quoteStrategy->getColumnName(
|
||||||
$columnName,
|
$columnName,
|
||||||
$dqlAliasToClassMap[$dqlAliasForFieldAlias],
|
$dqlAliasToClassMap[$dqlAliasForFieldAlias],
|
||||||
$this->_em->getConnection()->getDatabasePlatform()
|
$this->_em->getConnection()->getDatabasePlatform()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Get the SQL table alias for the entity and field
|
||||||
$sqlTableAliasForFieldAlias = $dqlAliasToSqlTableAliasMap[$dqlAliasForFieldAlias];
|
$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);
|
$searchPatterns[] = sprintf($fieldSearchPattern, $sqlTableAliasForFieldAlias, $columnName);
|
||||||
$replacements[] = $fieldAlias;
|
$replacements[] = $fieldAlias;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ use Doctrine\Tests\Models\CMS\CmsEmail;
|
||||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||||
use Doctrine\Tests\Models\CMS\CmsGroup;
|
use Doctrine\Tests\Models\CMS\CmsGroup;
|
||||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||||
|
use Doctrine\Tests\Models\Company\CompanyManager;
|
||||||
use Doctrine\Tests\Models\Pagination\Company;
|
use Doctrine\Tests\Models\Pagination\Company;
|
||||||
use Doctrine\Tests\Models\Pagination\Department;
|
use Doctrine\Tests\Models\Pagination\Department;
|
||||||
use Doctrine\Tests\Models\Pagination\Logo;
|
use Doctrine\Tests\Models\Pagination\Logo;
|
||||||
|
@ -725,6 +726,14 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
$this->_em->persist($user);
|
$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();
|
$this->_em->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue