diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index a50cd8343..947774542 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -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']) ) { diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index df46aa30a..d9f7e30ca 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -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} * diff --git a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php index 120ad548d..2915fd2ed 100644 --- a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php @@ -47,7 +47,7 @@ class OneToManyPersister extends AbstractCollectionPersister 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); + return $persister->load(array($mapping['mappedBy'] => $coll->getOwner(), $mapping['indexBy'] => $index), null, null, array(), 0, 1); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php index 5d8fa0f2a..eb4dbe4d8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php @@ -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; } -} \ No newline at end of file +}