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:
parent
523697d0b6
commit
3555007f08
@ -48,7 +48,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
|
|||||||
throw new \BadMethodCallException("Selecting a collection by index is only supported on indexed collections.");
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,7 +47,7 @@ class OneToManyPersister extends AbstractCollectionPersister
|
|||||||
throw new \BadMethodCallException("Selecting a collection by index is only supported on indexed collections.");
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -549,6 +549,18 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
|
$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()
|
private function loadFixture()
|
||||||
{
|
{
|
||||||
$user1 = new \Doctrine\Tests\Models\CMS\CmsUser();
|
$user1 = new \Doctrine\Tests\Models\CMS\CmsUser();
|
||||||
|
Loading…
Reference in New Issue
Block a user