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().


  • 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.


	public function sync($id = null, array $data = [], array $options = []) {
		$defaults = ['materialize' => true, 'dematerialize' => false];
		$options += $defaults;
		$model = $this->_model;
		$key = [];

		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) : [$key => $id];
		$this->_increment = [];
		$this->_data = $this->_updated = ($key + $data + $this->_updated);