Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Commit

Permalink
Added ability to return documents without the id as the key in Cursor…
Browse files Browse the repository at this point in the history
…::toArray()
  • Loading branch information
jstout24 committed Nov 20, 2012
1 parent 807f9cc commit 36915a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Doctrine/MongoDB/Cursor.php
Expand Up @@ -317,11 +317,11 @@ public function valid()
return $this->mongoCursor->valid();
}

public function toArray()
public function toArray($useKeys = true)
{
$cursor = $this;
return $this->retry(function() use ($cursor) {
return iterator_to_array($cursor);
return $this->retry(function() use ($cursor, $useKeys) {
return iterator_to_array($cursor, $useKeys);
}, true);
}

Expand Down
17 changes: 17 additions & 0 deletions tests/Doctrine/MongoDB/Tests/CursorTest.php
Expand Up @@ -61,4 +61,21 @@ public function testGetSingleResultReturnsNull()
$cursor = $collection->createQueryBuilder()->getQuery()->execute();
$this->assertNull($cursor->getSingleResult());
}

public function testToArray()
{
$this->assertEquals(
array(
(string) $this->doc1['_id'] => $this->doc1,
(string) $this->doc2['_id'] => $this->doc2,
(string) $this->doc3['_id'] => $this->doc3
),
$this->cursor->toArray()
);
}

public function testToArrayWithoutKeys()
{
$this->assertEquals(array($this->doc1, $this->doc2, $this->doc3), $this->cursor->toArray(false));
}
}

0 comments on commit 36915a3

Please sign in to comment.