Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/Doctrine/ODM/MongoDB/DocumentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,21 @@ public function find($id, $lockMode = LockMode::NONE, $lockVersion = null)
}

if ($lockMode == LockMode::NONE) {
return $this->uow->getDocumentPersister($this->documentName)->load($id);
return $this->getDocumentPersister()->load($id);
}

if ($lockMode == LockMode::OPTIMISTIC) {
if (!$this->class->isVersioned) {
throw LockException::notVersioned($this->documentName);
}
$document = $this->uow->getDocumentPersister($this->documentName)->load($id);
$document = $this->getDocumentPersister()->load($id);

$this->uow->lock($document, $lockMode, $lockVersion);

return $document;
}

return $this->uow->getDocumentPersister($this->documentName)->load($id, null, array(), $lockMode);
return $this->getDocumentPersister()->load($id, null, array(), $lockMode);
}

/**
Expand All @@ -161,11 +161,12 @@ public function findAll()
* @param array $sort Sort array for Cursor::sort()
* @param integer|null $limit Limit for Cursor::limit()
* @param integer|null $skip Skip for Cursor::skip()
* @return Cursor
*
* @return array The entities.
*/
public function findBy(array $criteria, array $sort = null, $limit = null, $skip = null)
{
return $this->uow->getDocumentPersister($this->documentName)->loadAll($criteria, $sort, $limit, $skip);
return iterator_to_array($this->getDocumentPersister()->loadAll($criteria, $sort, $limit, $skip), false);
}

/**
Expand All @@ -176,7 +177,7 @@ public function findBy(array $criteria, array $sort = null, $limit = null, $skip
*/
public function findOneBy(array $criteria)
{
return $this->uow->getDocumentPersister($this->documentName)->load($criteria);
return $this->getDocumentPersister()->load($criteria);
}

/**
Expand Down Expand Up @@ -279,4 +280,9 @@ public function matching(Criteria $criteria)
// @TODO: wrap around a specialized Collection for efficient count on large collections
return new ArrayCollection($queryBuilder->getQuery()->execute()->toArray());
}

protected function getDocumentPersister()
{
return $this->uow->getDocumentPersister($this->documentName);
}
}
2 changes: 1 addition & 1 deletion tests/Doctrine/ODM/MongoDB/Tests/Functional/CursorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testCursorShouldHydrateResults()
$this->dm->persist($user);
$this->dm->flush();

$cursor = $this->dm->getRepository('Documents\User')->findAll();
$cursor = $this->uow->getDocumentPersister('Documents\User')->loadAll();

$cursor->next();
$this->assertSame($user, $cursor->current());
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testBatchInsertCustomId()

$users = $this->dm->getRepository("Documents\User")->findAll();

$this->assertEquals(2, $users->count());
$this->assertCount(2, $users);

$results = array();
foreach ($users as $user) {
Expand All @@ -90,7 +90,7 @@ public function testBatchInsertCustomId()

$users = $this->dm->getRepository("Documents\CustomUser")->findAll();

$this->assertEquals(1, $users->count());
$this->assertCount(1, $users);

foreach ($users as $user) {
if ($user->getId() === 'userId') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function testFindAll()
{
$users = $this->repository->findAll();

$this->assertInstanceOf('Doctrine\ODM\MongoDB\Cursor', $users);
$this->assertEquals(1, count($users));
$this->assertInternalType('array', $users);
$this->assertCount(1, $users);
}

public function testFind()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testDocumentPersisterShouldClearQueuedInsertsOnMongoException()

$repository = $this->dm->getRepository($class);

$this->assertEquals(0, $repository->findAll()->count());
$this->assertCount(0, $repository->findAll());

// Create, persist and flush initial object
$doc1 = new GH580Document();
Expand Down Expand Up @@ -54,7 +54,7 @@ public function testDocumentPersisterShouldClearQueuedInsertsOnMongoException()
/* Repository should contain one object, but may contain two if the
* DocumentPersister was not cleaned up.
*/
$this->assertEquals(1, $repository->findAll()->count());
$this->assertCount(1, $repository->findAll());
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Documents/CommentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class CommentRepository extends DocumentRepository
{
public function findOneComment()
{
return $this->findBy(array())
return $this->getDocumentPersister()->loadAll()
->sort(array('date' => 'desc'))
->limit(1)
->getSingleResult();
}

public function findManyComments()
{
return $this->findBy(array());
return $this->getDocumentPersister()->loadAll();
}
}