From 965427b8f7ebceb4c3f3526236d7450204fefac7 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 16 Dec 2013 20:53:58 -0600
Subject: [PATCH] orm: Fix serious logic issue in the save() method

---
 include/class.orm.php | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/class.orm.php b/include/class.orm.php
index de47d422e..38d3482da 100644
--- a/include/class.orm.php
+++ b/include/class.orm.php
@@ -160,16 +160,18 @@ class VerySimpleModel {
         $filter = $fields = array();
         if (count($this->dirty) === 0)
             return;
-        foreach ($this->dirty as $field=>$old)
-            if ($this->__new__ or !in_array($field, $pk))
+        foreach ($this->dirty as $field=>$old) {
+            if ($this->__new__ or !in_array($field, $pk)) {
                 if (@get_class($this->get($field)) == 'SqlFunction')
                     $fields[] = $field.' = '.$this->get($field)->toSql();
                 else
                     $fields[] = $field.' = '.db_input($this->get($field));
-        foreach ($pk as $p)
-            $filter[] = $p.' = '.db_input($this->get($p));
+            }
+        }
         $sql .= ' SET '.implode(', ', $fields);
         if (!$this->__new__) {
+            foreach ($pk as $p)
+                $filter[] = $p.' = '.db_input($this->get($p));
             $sql .= ' WHERE '.implode(' AND ', $filter);
             $sql .= ' LIMIT 1';
         }
-- 
GitLab