Merge branch 'DDC-1685'
This commit is contained in:
commit
47ac61b3e0
@ -87,15 +87,14 @@ class CountOutputWalker extends SqlWalker
|
||||
throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction");
|
||||
}
|
||||
|
||||
$rootClass = $from[0]->rangeVariableDeclaration->abstractSchemaName;
|
||||
$rootAlias = $from[0]->rangeVariableDeclaration->aliasIdentificationVariable;
|
||||
|
||||
// Get the identity properties from the metadata
|
||||
$rootIdentifier = $this->queryComponents[$rootAlias]['metadata']->identifier;
|
||||
$rootClass = $this->queryComponents[$rootAlias]['metadata'];
|
||||
$rootIdentifier = $rootClass->identifier;
|
||||
|
||||
// For every identifier, find out the SQL alias by combing through the ResultSetMapping
|
||||
$sqlIdentifier = array();
|
||||
foreach ($rootIdentifier as $property) {
|
||||
if (isset($rootClass->fieldMappings[$property])) {
|
||||
foreach (array_keys($this->rsm->fieldMappings, $property) as $alias) {
|
||||
if ($this->rsm->columnOwnerMap[$alias] == $rootAlias) {
|
||||
$sqlIdentifier[$property] = $alias;
|
||||
@ -103,6 +102,17 @@ class CountOutputWalker extends SqlWalker
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($rootClass->associationMappings[$property])) {
|
||||
$joinColumn = $rootClass->associationMappings[$property]['joinColumns'][0]['name'];
|
||||
|
||||
foreach (array_keys($this->rsm->metaMappings, $joinColumn) as $alias) {
|
||||
if ($this->rsm->columnOwnerMap[$alias] == $rootAlias) {
|
||||
$sqlIdentifier[$property] = $alias;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($rootIdentifier) != count($sqlIdentifier)) {
|
||||
throw new \RuntimeException(sprintf(
|
||||
'Not all identifier properties can be found in the ResultSetMapping: %s',
|
||||
|
@ -63,12 +63,18 @@ class CountWalker extends TreeWalkerAdapter
|
||||
$root = reset($rootComponents);
|
||||
$parentName = key($root);
|
||||
$parent = current($root);
|
||||
$identifierFieldName = $parent['metadata']->getSingleIdentifierFieldName();
|
||||
|
||||
$pathType = PathExpression::TYPE_STATE_FIELD;
|
||||
if (isset($parent['metadata']->associationMappings[$identifierFieldName])) {
|
||||
$pathType = PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION;
|
||||
}
|
||||
|
||||
$pathExpression = new PathExpression(
|
||||
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $parentName,
|
||||
$parent['metadata']->getSingleIdentifierFieldName()
|
||||
$identifierFieldName
|
||||
);
|
||||
$pathExpression->type = PathExpression::TYPE_STATE_FIELD;
|
||||
$pathExpression->type = $pathType;
|
||||
|
||||
$distinct = $this->_getQuery()->getHint(self::HINT_DISTINCT);
|
||||
$AST->selectClause->selectExpressions = array(
|
||||
|
@ -98,16 +98,14 @@ class LimitSubqueryOutputWalker extends SqlWalker
|
||||
throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction");
|
||||
}
|
||||
|
||||
$rootClass = $from[0]->rangeVariableDeclaration->abstractSchemaName;
|
||||
$rootAlias = $from[0]->rangeVariableDeclaration->aliasIdentificationVariable;
|
||||
|
||||
// Get the identity properties from the metadata
|
||||
$metadata = $this->queryComponents[$rootAlias]['metadata'];
|
||||
$rootIdentifier = $metadata->identifier;
|
||||
$rootClass = $this->queryComponents[$rootAlias]['metadata'];
|
||||
$rootIdentifier = $rootClass->identifier;
|
||||
|
||||
// For every identifier, find out the SQL alias by combing through the ResultSetMapping
|
||||
$sqlIdentifier = array();
|
||||
foreach ($rootIdentifier as $property) {
|
||||
if (isset($rootClass->fieldMappings[$property])) {
|
||||
foreach (array_keys($this->rsm->fieldMappings, $property) as $alias) {
|
||||
if ($this->rsm->columnOwnerMap[$alias] == $rootAlias) {
|
||||
$sqlIdentifier[$property] = $alias;
|
||||
@ -115,6 +113,17 @@ class LimitSubqueryOutputWalker extends SqlWalker
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($rootClass->associationMappings[$property])) {
|
||||
$joinColumn = $rootClass->associationMappings[$property]['joinColumns'][0]['name'];
|
||||
|
||||
foreach (array_keys($this->rsm->metaMappings, $joinColumn) as $alias) {
|
||||
if ($this->rsm->columnOwnerMap[$alias] == $rootAlias) {
|
||||
$sqlIdentifier[$property] = $alias;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($rootIdentifier) != count($sqlIdentifier)) {
|
||||
throw new \RuntimeException(sprintf(
|
||||
'Not all identifier properties can be found in the ResultSetMapping: %s',
|
||||
|
@ -74,6 +74,10 @@ class LimitSubqueryWalker extends TreeWalkerAdapter
|
||||
}
|
||||
|
||||
$identifier = $parent['metadata']->getSingleIdentifierFieldName();
|
||||
if (isset($parent['metadata']->associationMappings[$identifier])) {
|
||||
throw new \RuntimeException("Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator.");
|
||||
}
|
||||
|
||||
$this->_getQuery()->setHint(
|
||||
self::IDENTIFIER_TYPE,
|
||||
Type::getType($parent['metadata']->getTypeOfField($identifier))
|
||||
|
@ -84,11 +84,15 @@ class WhereInWalker extends TreeWalkerAdapter
|
||||
$root = reset($rootComponents);
|
||||
$parentName = key($root);
|
||||
$parent = current($root);
|
||||
$identifierFieldName = $parent['metadata']->getSingleIdentifierFieldName();
|
||||
|
||||
$pathExpression = new PathExpression(
|
||||
PathExpression::TYPE_STATE_FIELD, $parentName, $parent['metadata']->getSingleIdentifierFieldName()
|
||||
);
|
||||
$pathExpression->type = PathExpression::TYPE_STATE_FIELD;
|
||||
$pathType = PathExpression::TYPE_STATE_FIELD;
|
||||
if (isset($parent['metadata']->associationMappings[$identifierFieldName])) {
|
||||
$pathType = PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION;
|
||||
}
|
||||
|
||||
$pathExpression = new PathExpression(PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $parentName, $identifierFieldName);
|
||||
$pathExpression->type = $pathType;
|
||||
|
||||
$count = $this->_getQuery()->getHint(self::HINT_PAGINATOR_ID_COUNT);
|
||||
|
||||
|
64
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php
Normal file
64
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Tests\Models\DDC117\DDC117ArticleDetails;
|
||||
use Doctrine\Tests\Models\DDC117\DDC117Article;
|
||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||
|
||||
/**
|
||||
* @group DDC-1685
|
||||
*/
|
||||
class DDC1685Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
private $paginator;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->useModelSet('ddc117');
|
||||
parent::setUp();
|
||||
|
||||
$this->_em->createQuery('DELETE FROM Doctrine\Tests\Models\DDC117\DDC117ArticleDetails ad')->execute();
|
||||
|
||||
$article = new DDC117Article("Foo");
|
||||
$this->_em->persist($article);
|
||||
$this->_em->flush();
|
||||
|
||||
$articleDetails = new DDC117ArticleDetails($article, "Very long text");
|
||||
$this->_em->persist($articleDetails);
|
||||
$this->_em->flush();
|
||||
|
||||
$dql = "SELECT ad FROM Doctrine\Tests\Models\DDC117\DDC117ArticleDetails ad";
|
||||
$query = $this->_em->createQuery($dql);
|
||||
|
||||
$this->paginator = new Paginator($query);
|
||||
}
|
||||
|
||||
public function testPaginateCount()
|
||||
{
|
||||
$this->assertEquals(1, count($this->paginator));
|
||||
}
|
||||
|
||||
public function testPaginateIterate()
|
||||
{
|
||||
foreach ($this->paginator as $ad) {
|
||||
$this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails', $ad);
|
||||
}
|
||||
}
|
||||
|
||||
public function testPaginateCountNoOutputWalkers()
|
||||
{
|
||||
$this->paginator->setUseOutputWalkers(false);
|
||||
$this->assertEquals(1, count($this->paginator));
|
||||
}
|
||||
|
||||
public function testPaginateIterateNoOutputWalkers()
|
||||
{
|
||||
$this->paginator->setUseOutputWalkers(false);
|
||||
|
||||
$this->setExpectedException('RuntimeException', 'Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator.');
|
||||
foreach ($this->paginator as $ad) {
|
||||
$this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails', $ad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user