You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running Doctrine\ODM\MongoDB\Cursor::getSingleResult() will clear limit from Cursor.
Example Code
<?php
$objects = $myObjectRepo->createQueryBuilder()
->limit(10)
->getQuery()
->execute();
// Access First Result:
$firstObject = $objects->getSingleResult();
// limit has been removed from $objects.
Reason
This is the implementation of getSingleResult from Doctrine\MongoDB\Cursor.
public function getSingleResult()
{
$originalLimit = $this->limit;
$this->reset();
$this->limit(1);
$result = current($this->toArray(false)) ?: null;
$this->reset();
$this->limit($originalLimit);
return $result;
}
It's retrieving the cursors value using $this->limit. Since Doctrine\ODM\MongoDB\Cursor extends Doctrine\MongoDB\Cursor, it has a cursor property. Doctrine\ODM\MongoDB\Cursor acts as decorator for Doctrine\MongoDB\Cursor and should return all values from Doctrine\ODM\MongoDB\Cursor::$baseCursor. Accessing the property breaks or ignores this design and returns the null $limit value of Doctrine\ODM\MongoDB\Cursor.
This could be fixed by creating a protected accessor $this->getLimit() on both Cursors, the ODM cursor though would return the result of $this->baseCursor->getLimit().
The text was updated successfully, but these errors were encountered:
Issue
Running
Doctrine\ODM\MongoDB\Cursor::getSingleResult()
will clear limit from Cursor.Example Code
Reason
This is the implementation of
getSingleResult
fromDoctrine\MongoDB\Cursor
.It's retrieving the cursors value using
$this->limit
. SinceDoctrine\ODM\MongoDB\Cursor
extendsDoctrine\MongoDB\Cursor
, it has acursor
property.Doctrine\ODM\MongoDB\Cursor
acts as decorator forDoctrine\MongoDB\Cursor
and should return all values fromDoctrine\ODM\MongoDB\Cursor::$baseCursor
. Accessing the property breaks or ignores this design and returns the null$limit
value ofDoctrine\ODM\MongoDB\Cursor
.This could be fixed by creating a protected accessor
$this->getLimit()
on both Cursors, the ODM cursor though would return the result of$this->baseCursor->getLimit()
.The text was updated successfully, but these errors were encountered: