lithium\data\entity\Document::sync PHP Метод

sync() публичный Метод

Extends the parent implementation to ensure that child documents are properly synced as well.
public sync ( mixed $id = null, array $data = [], array $options = [] ) : void
$id mixed
$data array
$options array Options when calling this method: - `'recursive'` _boolean_: If `true` attempts to sync nested objects as well. Otherwise, only syncs the current object. Defaults to `true`.
Результат void
    public function sync($id = null, array $data = array(), array $options = array())
    {
        $defaults = array('recursive' => true);
        $options += $defaults;
        if (!$options['recursive']) {
            return parent::sync($id, $data, $options);
        }
        foreach ($this->_updated as $key => $val) {
            if (is_object($val) && method_exists($val, 'sync')) {
                $nested = isset($data[$key]) ? $data[$key] : array();
                $this->_updated[$key]->sync(null, $nested, $options);
            }
        }
        parent::sync($id, $data, $options);
    }

Usage Example

 /**
  * Tests that arrays of nested objects can be appended to and will be updated using the proper
  * MongoDB operators.
  */
 public function testAppendingNestedObjectArray()
 {
     $model = $this->_model;
     $model::schema(false);
     $model::schema(array('accounts' => array('type' => 'object', 'array' => true), 'accounts.name' => array('type' => 'string')));
     $doc = new Document(compact('model'));
     $this->assertEqual(array(), $doc->accounts->data());
     $doc->sync();
     $data = array('name' => 'New account');
     $doc->accounts[] = new Document(compact('data'));
     $result = Exporter::get('update', $doc->export());
     $expected = array('update' => array('accounts.0' => $data));
     $this->assertEqual($expected, $result);
     $result = Exporter::toCommand($result);
     $expected = array('$set' => array('accounts.0' => $data));
     $this->assertEqual($expected, $result);
 }
All Usage Examples Of lithium\data\entity\Document::sync