Model/Behavior/RevisionBehavior.php
public function diff(Model $Model, $fromVersionId = null, $toVersionId = null, $options = array()) {
		if (!$Model->id) {
			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING);
			return array();
		}
		if (!$Model->ShadowModel) {
			trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
			return array();
		}
		if (isset($options['conditions'])) {
			$conditions = array_merge($options['conditions'], array($Model->primaryKey => $Model->id));
		} else {
			$conditions = array($Model->primaryKey => $Model->id);
		}
		if (is_numeric($fromVersionId) || is_numeric($toVersionId)) {
			if (is_numeric($fromVersionId) && is_numeric($toVersionId)) {
				$conditions['version_id'] = array($fromVersionId, $toVersionId);
				if ($Model->ShadowModel->find('count', array('conditions' => $conditions)) < 2) {
					return array();
				}
			} else {
				if (is_numeric($fromVersionId)) {
					$conditions['version_id'] = $fromVersionId;
				} else {
					$conditions['version_id'] = $toVersionId;
				}
				if ($Model->ShadowModel->find('count', array('conditions' => $conditions)) < 1) {
					return array();
				}
			}
		}
		$conditions = array($Model->primaryKey => $Model->id);
		if (is_numeric($fromVersionId)) {
			$conditions['version_id >='] = $fromVersionId;
		}
		if (is_numeric($toVersionId)) {
			$conditions['version_id <='] = $toVersionId;
		}
		$options['conditions'] = $conditions;
		$all = $this->revisions($Model, $options, true);
		if (!$all) {
			return array();
		}
		$unified = array();
		$keys = array_keys($all[0][$Model->alias]);
		foreach ($keys as $field) {
			$allValues = Hash::extract($all, '{n}.' . $Model->alias . '.' . $field);
			$allValues = array_reverse(array_unique(array_reverse($allValues, true)), true);
			if (sizeof($allValues) == 1) {
				$unified[$field] = reset($allValues);
			} else {
				$unified[$field] = $allValues;
			}
		}
		return array($Model->alias => $unified);
	}
public function diff(Model $Model, $fromVersionId = null, $toVersionId = null, $options = array()) {
		if (!$Model->id) {
			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING);
			return array();
		}
		if (!$Model->ShadowModel) {
			trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
			return array();
		}
		if (isset($options['conditions'])) {
			$conditions = array_merge($options['conditions'], array($Model->primaryKey => $Model->id));
		} else {
			$conditions = array($Model->primaryKey => $Model->id);
		}
		if (is_numeric($fromVersionId) || is_numeric($toVersionId)) {
			if (is_numeric($fromVersionId) && is_numeric($toVersionId)) {
				$conditions['version_id'] = array($fromVersionId, $toVersionId);
				if ($Model->ShadowModel->find('count', array('conditions' => $conditions)) < 2) {
					return array();
				}
			} else {
				if (is_numeric($fromVersionId)) {
					$conditions['version_id'] = $fromVersionId;
				} else {
					$conditions['version_id'] = $toVersionId;
				}
				if ($Model->ShadowModel->find('count', array('conditions' => $conditions)) < 1) {
					return array();
				}
			}
		}
		$conditions = array($Model->primaryKey => $Model->id);
		if (is_numeric($fromVersionId)) {
			$conditions['version_id >='] = $fromVersionId;
		}
		if (is_numeric($toVersionId)) {
			$conditions['version_id <='] = $toVersionId;
		}
		$options['conditions'] = $conditions;
		$all = $this->revisions($Model, $options, true);
		if (!$all) {
			return array();
		}
		$unified = array();
		$keys = array_keys($all[0][$Model->alias]);
		foreach ($keys as $field) {
			$allValues = Hash::extract($all, '{n}.' . $Model->alias . '.' . $field);
			$allValues = array_reverse(array_unique(array_reverse($allValues, true)), true);
			if (sizeof($allValues) == 1) {
				$unified[$field] = reset($allValues);
			} else {
				$unified[$field] = $allValues;
			}
		}
		return array($Model->alias => $unified);
	}
public function diff ( Model $ Model , $ fromVersionId = null , $ toVersionId = null , $ options = array ( ) ) { if ( ! $ Model -> id ) { trigger_error ( 'RevisionBehavior: Model::id must be set' , E_USER_WARNING ) ; return array ( ) ; } if ( ! $ Model -> ShadowModel ) { trigger_error ( 'RevisionBehavior: ShadowModel doesnt exist.' , E_USER_WARNING ) ; return array ( ) ; } if ( isset ( $ options [ 'conditions' ] ) ) { $ conditions = array_merge ( $ options [ 'conditions' ] , array ( $ Model -> primaryKey => $ Model -> id ) ) ; } else { $ conditions = array ( $ Model -> primaryKey => $ Model -> id ) ; } if ( is_numeric ( $ fromVersionId ) || is_numeric ( $ toVersionId ) ) { if ( is_numeric ( $ fromVersionId ) && is_numeric ( $ toVersionId ) ) { $ conditions [ 'version_id' ] = array ( $ fromVersionId , $ toVersionId ) ; if ( $ Model -> ShadowModel -> find ( 'count' , array ( 'conditions' => $ conditions ) ) < 2 ) { return array ( ) ; } } else { if ( is_numeric ( $ fromVersionId ) ) { $ conditions [ 'version_id' ] = $ fromVersionId ; } else { $ conditions [ 'version_id' ] = $ toVersionId ; } if ( $ Model -> ShadowModel -> find ( 'count' , array ( 'conditions' => $ conditions ) ) < 1 ) { return array ( ) ; } } } $ conditions = array ( $ Model -> primaryKey => $ Model -> id ) ; if ( is_numeric ( $ fromVersionId ) ) { $ conditions [ 'version_id >=' ] = $ fromVersionId ; } if ( is_numeric ( $ toVersionId ) ) { $ conditions [ 'version_id <=' ] = $ toVersionId ; } $ options [ 'conditions' ] = $ conditions ; $ all = $ this -> revisions ( $ Model , $ options , true ) ; if ( ! $ all ) { return array ( ) ; } $ unified = array ( ) ; $ keys = array_keys ( $ all [ 0 ] [ $ Model -> alias ] ) ; foreach ( $ keys as $ field ) { $ allValues = Hash :: extract ( $ all , '{n}.' . $ Model -> alias . '.' . $ field ) ; $ allValues = array_reverse ( array_unique ( array_reverse ( $ allValues , true ) ) , true ) ; if ( sizeof ( $ allValues ) == 1 ) { $ unified [ $ field ] = reset ( $ allValues ) ; } else { $ unified [ $ field ] = $ allValues ; } } return array ( $ Model -> alias => $ unified ) ; }
Returns an array that maps to the Model, only with multiple values for fields that has been changed

@example $this->Post->id = 4; $changes = $this->Post->diff();
@example $this->Post->id = 4; $myChanges = $this->Post->diff(null,nul, array('conditions'=>array('user_id'=>4)));
@example $this->Post->id = 4; $difference = $this->Post->diff(45,192);
@param Object $Model
@param int $fromVersionId
@param int $toVersionId
@param array $options
@return array
Returns an array that maps to the Model only with multiple values for fields that has been changed