a-musing-moose/morph — Issue #25: Get single Document
Author: russellseymour
Created: 2012-01-16 15:17:04+00:00
State: open

Hello again,

I feel that I might be missing something very obvious here again, so please accept my apologies in advance.

Sometimes I run a query that I know will return either 0 or 1 records. Testing for the count is easy, however I am having problems with the iterator object when I want to get the 1 document that is returned.

I have tried to use the next() and current() methods, but I do not get a valid object back. Indeed i get the following error when I used current():

```PHP Catchable fatal error: Argument 1 passed to morph\Iterator::createObject() must be an array, null given, called in phar:///turtle/ngsites/shared/phplib/Morph.phar/Iterator.php on line 104 and defined in phar:///turtle/ngsites/shared/phplib/Morph.phar/Iterator.php on line 86```

The only way that I have been able to get the single document into an object is to run the foreach command, e.g.:

```foreach ($result as $stored) {}```

But that does not feel right.

Thanks again,

Russell