lithium\data\Entity::sync()

public method

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 $id

    The ID to assign, where applicable.

  • array $data

    Any additional generated data assigned to the object by the database.

  • array $options

    Method options:

    • 'materialize' boolean: Determines whether or not the flag should be set that indicates that this entity exists in the data store. Defaults to true.
    • 'dematerialize' boolean: If set to true, indicates that this entity has been deleted from the data store and no longer exists. Defaults to false.

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);
	}