`Document` is an alternative to the `entity\Record` class, which is optimized for
organizing collections of entities from document-oriented databases such as CouchDB or MongoDB.
A `Document` object's fields can represent a collection of both simple and complex data types,
as well as other `Document` objects. Given the following data (document) structure:
{{{
{
_id: 12345.
name: 'Acme, Inc.',
employees: {
'Larry': { email: 'larry@acme.com' },
'Curly': { email: 'curly@acme.com' },
'Moe': { email: 'moe@acme.com' }
}
}
}}}
You can query the object as follows:
{{{$acme = Company::find(12345);}}}
This returns a `Document` object, populated with the raw representation of the data.
{{{print_r($acme->to('array'));
// Yields:
// array(
// '_id' => 12345,
// 'name' => 'Acme, Inc.',
// 'employees' => array(
// 'Larry' => array('email' => 'larry@acme.com'),
// 'Curly' => array('email' => 'curly@acme.com'),
// 'Moe' => array('email' => 'moe@acme.com')
// )
//)}}}
As with other database objects, a `Document` exposes its fields as object properties, like so:
{{{echo $acme->name; // echoes 'Acme, Inc.'}}}
However, accessing a field containing a data set will return that data set wrapped in a
sub-`Document` object., i.e.:
{{{$employees = $acme->employees;
// returns a Document object with the data in 'employees'}}}