1
0
mirror of synced 2024-12-14 15:16:04 +03:00

Return NULL for non-existent keys

The load() function already returns just one entity or NULL, so
the current() is not needed and the result can be returned directly.
This commit is contained in:
Sander Marechal 2013-06-20 10:09:52 +02:00
parent 523697d0b6
commit 3555007f08
3 changed files with 14 additions and 2 deletions

View File

@ -48,7 +48,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
throw new \BadMethodCallException("Selecting a collection by index is only supported on indexed collections.");
}
return current($persister->load(array($mapping['indexBy'] => $index), null, null, array(), 0, 1));
return $persister->load(array($mapping['indexBy'] => $index), null, null, array(), 0, 1);
}
/**

View File

@ -47,7 +47,7 @@ class OneToManyPersister extends AbstractCollectionPersister
throw new \BadMethodCallException("Selecting a collection by index is only supported on indexed collections.");
}
return current($persister->load(array($mapping['indexBy'] => $index), null, null, array(), 0, 1));
return $persister->load(array($mapping['indexBy'] => $index), null, null, array(), 0, 1);
}
/**

View File

@ -549,6 +549,18 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
}
/**
* @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()
{
$user1 = new \Doctrine\Tests\Models\CMS\CmsUser();