1
0
mirror of synced 2025-01-31 04:21:44 +03:00

Remove extra-lazy-get for ManyToMany relation

This commit is contained in:
Sander Marechal 2013-06-27 14:19:39 +02:00
parent 5635fa60a4
commit 06ed21e883
3 changed files with 2 additions and 41 deletions

View File

@ -518,6 +518,7 @@ final class PersistentCollection implements Collection, Selectable
public function get($key)
{
if ( ! $this->initialized
&& $this->association['type'] === Mapping\ClassMetadataInfo::ONE_TO_MANY
&& $this->association['fetch'] === Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY
&& isset($this->association['indexBy'])
) {

View File

@ -33,24 +33,6 @@ use Doctrine\ORM\UnitOfWork;
*/
class ManyToManyPersister extends AbstractCollectionPersister
{
/**
* {@inheritdoc}
*
* @override
*/
public function get(PersistentCollection $coll, $index)
{
$mapping = $coll->getMapping();
$uow = $this->em->getUnitOfWork();
$persister = $uow->getEntityPersister($mapping['targetEntity']);
if (!isset($mapping['indexBy'])) {
throw new \BadMethodCallException("Selecting a collection by index is only supported on indexed collections.");
}
return $persister->load(array($mapping['indexBy'] => $index), null, null, array(), 0, 1);
}
/**
* {@inheritdoc}
*

View File

@ -17,7 +17,6 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
private $groupId;
private $articleId;
private $groupname;
private $topic;
private $phonenumber;
@ -562,33 +561,13 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertSame($article, $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId));
}
/**
* @group DDC-1398
*/
public function testGetIndexByManyToMany()
{
$user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
/* @var $user CmsUser */
$queryCount = $this->getCurrentQueryCount();
$group = $user->groups->get($this->groupname);
$this->assertFalse($user->groups->isInitialized());
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
$this->assertSame($group, $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId));
}
/**
* @group DDC-1398
*/
public function testGetNonExistentIndexBy()
{
$user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
/* @var $user CmsUser */
$this->assertNull($user->articles->get(-1));
$this->assertNull($user->groups->get(-1));
}
private function loadFixture()
@ -668,8 +647,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->userId = $user1->getId();
$this->groupId = $group1->id;
$this->groupname = $group1->name;
$this->topic = $article1->topic;
$this->phonenumber = $phonenumber1->phonenumber;
}
}
}