lithium\data\entity\Document::sync()
Overrides
lithium\data\Entity::sync()
Extends the parent implementation to ensure that child documents are properly synced as well.
Parameters
-
mixed
$id
-
array
$data
-
array
$options
Options when calling this method:
'recursive'
boolean: Iftrue
attempts to sync nested objects as well. Otherwise, only syncs the current object. Defaults totrue
.
Returns
voidSource
public function sync($id = null, array $data = [], array $options = []) {
$defaults = ['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] : [];
$this->_updated[$key]->sync(null, $nested, $options);
}
}
parent::sync($id, $data, $options);
}