fix extra lazy count
This commit is contained in:
parent
fe11831bd7
commit
632d13ba0c
@ -1160,7 +1160,7 @@ class BasicEntityPersister
|
|||||||
$conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableName . '.' . $quotedSourceColumn;
|
$conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableName . '.' . $quotedSourceColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ' INNER JOIN ' . $joinTableName . ' ON ' . implode(' AND ', $conditions);
|
return ' INNER JOIN ' . $joinTableName . ' ON ' . implode(' AND ', $conditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -212,41 +212,42 @@ class ManyToManyPersister extends AbstractCollectionPersister
|
|||||||
*/
|
*/
|
||||||
public function count(PersistentCollection $coll)
|
public function count(PersistentCollection $coll)
|
||||||
{
|
{
|
||||||
$mapping = $filterMapping = $coll->getMapping();
|
$conditions = array();
|
||||||
$class = $this->_em->getClassMetadata($mapping['sourceEntity']);
|
$params = array();
|
||||||
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($coll->getOwner());
|
$mapping = $coll->getMapping();
|
||||||
|
$association = $mapping;
|
||||||
|
$class = $this->_em->getClassMetadata($mapping['sourceEntity']);
|
||||||
|
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($coll->getOwner());
|
||||||
|
|
||||||
if ($mapping['isOwningSide']) {
|
if ( ! $mapping['isOwningSide']) {
|
||||||
$joinColumns = $mapping['relationToSourceKeyColumns'];
|
$targetEntity = $this->_em->getClassMetadata($mapping['targetEntity']);
|
||||||
} else {
|
$association = $targetEntity->associationMappings[$mapping['mappedBy']];
|
||||||
$mapping = $this->_em->getClassMetadata($mapping['targetEntity'])->associationMappings[$mapping['mappedBy']];
|
|
||||||
$joinColumns = $mapping['relationToTargetKeyColumns'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$whereClauses = array();
|
$joinColumns = ( ! $mapping['isOwningSide'])
|
||||||
$params = array();
|
? $association['joinTable']['inverseJoinColumns']
|
||||||
|
: $association['joinTable']['joinColumns'];
|
||||||
|
|
||||||
foreach ($mapping['joinTableColumns'] as $joinTableColumn) {
|
foreach ($joinColumns as $joinColumn) {
|
||||||
if ( ! isset($joinColumns[$joinTableColumn])) {
|
$columnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
|
||||||
continue;
|
$referencedName = $joinColumn['referencedColumnName'];
|
||||||
}
|
$conditions[] = $columnName . ' = ?';
|
||||||
|
$params[] = ($class->containsForeignIdentifier)
|
||||||
$whereClauses[] = $joinTableColumn . ' = ?';
|
? $id[$class->getFieldForColumn($referencedName)]
|
||||||
|
: $id[$class->fieldNames[$referencedName]];
|
||||||
$params[] = ($class->containsForeignIdentifier)
|
|
||||||
? $id[$class->getFieldForColumn($joinColumns[$joinTableColumn])]
|
|
||||||
: $id[$class->fieldNames[$joinColumns[$joinTableColumn]]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($filterMapping);
|
$joinTableName = $this->quoteStrategy->getJoinTableName($association, $class, $this->platform);
|
||||||
|
list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($mapping);
|
||||||
|
|
||||||
if ($filterSql) {
|
if ($filterSql) {
|
||||||
$whereClauses[] = $filterSql;
|
$conditions[] = $filterSql;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(*)'
|
$sql = 'SELECT COUNT(*)'
|
||||||
. ' FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform) . ' t'
|
. ' FROM ' . $joinTableName . ' t'
|
||||||
. $joinTargetEntitySQL
|
. $joinTargetEntitySQL
|
||||||
. ' WHERE ' . implode(' AND ', $whereClauses);
|
. ' WHERE ' . implode(' AND ', $conditions);
|
||||||
|
|
||||||
return $this->_conn->fetchColumn($sql, $params);
|
return $this->_conn->fetchColumn($sql, $params);
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ class DDC1885Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertCount(1, $user->getGroups());
|
$this->assertCount(1, $user->getGroups());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testClearAll()
|
public function testClearAll()
|
||||||
{
|
{
|
||||||
$user = $this->user;
|
$user = $this->user;
|
||||||
$u1Id = $user->id;
|
$u1Id = $user->id;
|
||||||
@ -155,4 +155,19 @@ class DDC1885Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
|
|
||||||
$this->assertCount(0, $user->getGroups());
|
$this->assertCount(0, $user->getGroups());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCountExtraLazy()
|
||||||
|
{
|
||||||
|
$user = $this->user;
|
||||||
|
$u1Id = $user->id;
|
||||||
|
$user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $u1Id);
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Doctrine\Tests\Models\Quote\User', $user);
|
||||||
|
$this->assertEquals('FabioBatSilva', $user->name);
|
||||||
|
$this->assertEquals($u1Id, $user->id);
|
||||||
|
|
||||||
|
$this->assertCount(0, $user->extraLazyGroups);
|
||||||
|
$this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $user->getGroups()->get(0));
|
||||||
|
$this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $user->getGroups()->get(1));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user