lithium\data\Entity::sync()
Called after an Entity is saved. Updates the object's internal state to reflect the
corresponding database entity, and sets the Entity object's key, if this is a newly-created
object. Do not call this method if you intend to update the database's copy of the
entity. Instead, see Model::save().
Parameters
-
mixed
$idThe ID to assign, where applicable.
-
array
$dataAny additional generated data assigned to the object by the database.
-
array
$optionsMethod options:
'materialize'boolean: Determines whether or not the flag should be set that indicates that this entity exists in the data store. Defaults totrue.'dematerialize'boolean: If set totrue, indicates that this entity has been deleted from the data store and no longer exists. Defaults tofalse.
Source
public function sync($id = null, array $data = array(), array $options = array()) {
$defaults = array('materialize' => true, 'dematerialize' => false);
$options += $defaults;
$model = $this->_model;
$key = array();
if ($options['materialize']) {
$this->_exists = true;
}
if ($options['dematerialize']) {
$this->_exists = false;
}
if ($id && $model) {
$key = $model::meta('key');
$key = is_array($key) ? array_combine($key, $id) : array($key => $id);
}
$this->_increment = array();
$this->_data = $this->_updated = ($key + $data + $this->_updated);
}