From e8c4f00a8dd776a878d3fbb27747cdd5bfaf2a92 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 30 Sep 2015 21:18:41 +1000 Subject: [PATCH] Suppress DB updates when values are not changed --- modules/orm/classes/Kohana/ORM.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/orm/classes/Kohana/ORM.php b/modules/orm/classes/Kohana/ORM.php index 2c8d9d1..54f3a86 100644 --- a/modules/orm/classes/Kohana/ORM.php +++ b/modules/orm/classes/Kohana/ORM.php @@ -792,6 +792,20 @@ class Kohana_ORM extends Model implements serializable { // Object is no longer saved or valid $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])) {