public function testUpdateWithSubObjects()
{
$model = $this->_model;
$exists = true;
$model::config(array('meta' => array('key' => '_id')));
$schema = new Schema(array('fields' => array('forceArray' => array('type' => 'string', 'array' => true), 'array' => array('type' => 'string', 'array' => true), 'dictionary' => array('type' => 'string', 'array' => true), 'numbers' => array('type' => 'integer', 'array' => true), 'objects' => array('type' => 'object', 'array' => true), 'deeply' => array('type' => 'object', 'array' => true), 'foo' => array('type' => 'string'))));
$config = compact('model', 'schema', 'exists');
$doc = new Document($config + array('data' => array('numbers' => new DocumentSet($config + array('data' => array(7, 8, 9), 'pathKey' => 'numbers')), 'objects' => new DocumentSet($config + array('pathKey' => 'objects', 'data' => array(new Document($config + array('data' => array('foo' => 'bar'))), new Document($config + array('data' => array('foo' => 'baz')))))), 'deeply' => new Document($config + array('pathKey' => 'deeply', 'data' => array('nested' => 'object'))), 'foo' => 'bar')));
$doc->dictionary[] = 'A Word';
$doc->forceArray = 'Word';
$doc->array = array('one');
$doc->field = 'value';
$doc->objects[1]->foo = 'dib';
$doc->objects[] = array('foo' => 'diz');
$doc->deeply->nested = 'foo';
$doc->deeply->nestedAgain = 'bar';
$doc->array = array('one');
$doc->newObject = new Document(array('exists' => false, 'data' => array('subField' => 'subValue')));
$doc->newObjects = array(array('test' => 'one', 'another' => 'two'), array('three' => 'four'));
$this->assertEqual('foo', $doc->deeply->nested);
$this->assertEqual('subValue', $doc->newObject->subField);
$doc->numbers = array(8, 9);
$doc->numbers[] = 10;
$doc->numbers->append(11);
$export = $doc->export();
$result = Exporter::get('update', $doc->export());
$expected = array('array' => array('one'), 'dictionary' => array('A Word'), 'forceArray' => array('Word'), 'numbers' => array(8, 9, 10, 11), 'newObject' => array('subField' => 'subValue'), 'newObjects' => array(array('test' => 'one', 'another' => 'two'), array('three' => 'four')), 'field' => 'value', 'deeply.nested' => 'foo', 'deeply.nestedAgain' => 'bar', 'array' => array('one'), 'objects.1.foo' => 'dib', 'objects.2' => array('foo' => 'diz'));
$this->assertEqual($expected, $result['update']);
$doc->objects[] = array('foo' => 'dob');
$exist = $doc->objects->find(function ($data) {
return strcmp($data->foo, 'dob') === 0;
}, array('collect' => false));
$this->assertTrue(!empty($exist));
}