Suppress DB updates when values are not changed

This commit is contained in:
Deon George 2015-09-30 21:18:41 +10:00
parent c50a9c59ec
commit cb8c3f88f6

View File

@ -789,6 +789,20 @@ class Kohana_ORM extends Model implements serializable {
// Object is no longer saved or valid // Object is no longer saved or valid
$this->_saved = $this->_valid = FALSE; $this->_saved = $this->_valid = FALSE;
} }
// If the replacement value is the same as the original value, we dont need to update.
// @note This assumes that the value returned from the DB is always a string.
if (array_key_exists($column, $this->_original_values) AND (string)$value === $this->_original_values[$column] AND array_key_exists($column, $this->_changed))
{
unset($this->_changed[$column]);
// Reset back our saved status.
if (! count($this->_changed))
{
$this->_saved = $this->_valid = TRUE;
}
}
} }
elseif (isset($this->_belongs_to[$column])) elseif (isset($this->_belongs_to[$column]))
{ {