Skip to content

Loading…

EagerCursor should inherit hydrate option and hints from BaseCursor #547

Merged
merged 2 commits into from

1 participant

@jmikola
Doctrine member

This includes commits from #424, rebased atop master. There is an additional fix per @jwage's suggestion to copy cursor hints.

Additionally, the second commit adds tests for this improvement.

@jmikola jmikola merged commit 5abc5c8 into master

1 check passed

Details default The Travis build passed
@jmikola jmikola deleted the eager-cursor branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
2 lib/Doctrine/ODM/MongoDB/Query/Query.php
@@ -220,6 +220,8 @@ public function execute()
// Wrap odm cursor with EagerCursor if true
if ($this->query['eagerCursor'] === true) {
$results = new EagerCursor($results, $this->dm->getUnitOfWork(), $this->class);
+ $results->hydrate($this->hydrate);
+ $results->setHints($hints);
}
// GeoLocationFindQuery just returns an instance of ArrayIterator so we have to
View
19 tests/Doctrine/ODM/MongoDB/Tests/Functional/EagerCursorTest.php
@@ -2,6 +2,7 @@
namespace Doctrine\ODM\MongoDB\Tests\Functional;
+use Doctrine\ODM\MongoDB\Query\Query;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
class EagerCursorTest extends \Doctrine\ODM\MongoDB\Tests\BaseTest
@@ -25,6 +26,24 @@ public function setUp()
$this->test = $qb->getQuery()->execute();
}
+ public function testEagerCursorInheritsHydrateOptionAndHints()
+ {
+ $qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\EagerTestDocument')
+ ->refresh(true)
+ ->slaveOkay(true)
+ ->hydrate(false)
+ ->eagerCursor(true);
+
+ $eagerCursor = $qb->getquery()->execute();
+ $hints = $eagerCursor->getHints();
+
+ $this->assertArrayHasKey(Query::HINT_REFRESH, $hints);
+ $this->assertTrue(true, $hints[Query::HINT_REFRESH]);
+ $this->assertArrayHasKey(Query::HINT_SLAVE_OKAY, $hints);
+ $this->assertTrue(true, $hints[Query::HINT_SLAVE_OKAY]);
+ $this->assertTrue(is_array($eagerCursor->getSingleResult()));
+ }
+
public function testEagerCursor()
{
$this->assertInstanceOf('Doctrine\ODM\MongoDB\EagerCursor', $this->test);
Something went wrong with that request. Please try again.