Merge branch 'fix-many-many-criteria' of github.com:petitchevalroux/doctrine2 into many-to-many-criteria-fixes
Conflicts: lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php
This commit is contained in:
commit
ae785757a1
@ -280,6 +280,8 @@ class ManyToManyPersister extends AbstractCollectionPersister
|
||||
|
||||
$sql .= $this->getOrderingSql($criteria);
|
||||
|
||||
$sql .= $this->getLimitSql($criteria);
|
||||
|
||||
$stmt = $this->conn->executeQuery($sql, $params);
|
||||
|
||||
return $this
|
||||
@ -760,4 +762,19 @@ class ManyToManyPersister extends AbstractCollectionPersister
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Criteria $criteria
|
||||
* @return string
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
private function getLimitSql(Criteria $criteria)
|
||||
{
|
||||
$limit = $criteria->getMaxResults();
|
||||
$offset = $criteria->getFirstResult();
|
||||
if ($limit !== null || $offset !== null) {
|
||||
return $this->platform->modifyLimitQuery('', $limit, $offset);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@ -415,6 +415,69 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa
|
||||
$this->assertEquals(['A', 'B', 'C', 'Developers_0'], $existingOrder);
|
||||
}
|
||||
|
||||
public function testMatchingWithLimit()
|
||||
{
|
||||
$user = $this->addCmsUserGblancoWithGroups(2);
|
||||
$this->_em->clear();
|
||||
|
||||
$user = $this->_em->find(get_class($user), $user->id);
|
||||
|
||||
$groups = $user->groups;
|
||||
$this->assertFalse($user->groups->isInitialized(), "Pre-condition: lazy collection");
|
||||
|
||||
$criteria = Criteria::create()->setMaxResults(1);
|
||||
$result = $groups->matching($criteria);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
|
||||
$this->assertFalse($user->groups->isInitialized(), "Post-condition: matching does not initialize collection");
|
||||
}
|
||||
|
||||
public function testMatchingWithOffset()
|
||||
{
|
||||
$user = $this->addCmsUserGblancoWithGroups(2);
|
||||
$this->_em->clear();
|
||||
|
||||
$user = $this->_em->find(get_class($user), $user->id);
|
||||
|
||||
$groups = $user->groups;
|
||||
$this->assertFalse($user->groups->isInitialized(), "Pre-condition: lazy collection");
|
||||
|
||||
$criteria = Criteria::create()->setFirstResult(1);
|
||||
$result = $groups->matching($criteria);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
|
||||
$firstGroup = $result->first();
|
||||
$this->assertEquals('Developers_1', $firstGroup->name);
|
||||
|
||||
$this->assertFalse($user->groups->isInitialized(), "Post-condition: matching does not initialize collection");
|
||||
}
|
||||
|
||||
public function testMatchingWithLimitAndOffset()
|
||||
{
|
||||
$user = $this->addCmsUserGblancoWithGroups(5);
|
||||
$this->_em->clear();
|
||||
|
||||
$user = $this->_em->find(get_class($user), $user->id);
|
||||
|
||||
$groups = $user->groups;
|
||||
$this->assertFalse($user->groups->isInitialized(), "Pre-condition: lazy collection");
|
||||
|
||||
$criteria = Criteria::create()->setFirstResult(1)->setMaxResults(3);
|
||||
$result = $groups->matching($criteria);
|
||||
|
||||
$this->assertCount(3, $result);
|
||||
|
||||
$firstGroup = $result->first();
|
||||
$this->assertEquals('Developers_1', $firstGroup->name);
|
||||
|
||||
$lastGroup = $result->last();
|
||||
$this->assertEquals('Developers_3', $lastGroup->name);
|
||||
|
||||
$this->assertFalse($user->groups->isInitialized(), "Post-condition: matching does not initialize collection");
|
||||
}
|
||||
|
||||
public function testMatching()
|
||||
{
|
||||
$user = $this->addCmsUserGblancoWithGroups(2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user