diff --git a/library/Director/Data/Db/DbObject.php b/library/Director/Data/Db/DbObject.php index 71ab51dc8..14862d4e9 100644 --- a/library/Director/Data/Db/DbObject.php +++ b/library/Director/Data/Db/DbObject.php @@ -372,8 +372,11 @@ protected function reallySet($key, $value) return $this; } - $this->hasBeenModified = true; - $this->modifiedProperties[$key] = true; + if ($key !== $this->autoincKeyName) { + $this->hasBeenModified = true; + $this->modifiedProperties[$key] = true; + } + $this->properties[$key] = $value; return $this; } @@ -1014,6 +1017,17 @@ public function createWhere() $originalId ); } + + $key = $this->getKeyName(); + $val = $this->get($key); + if ($val) { + $this->properties[$this->autoincKeyName] = null; + return $this->db->quoteInto( + sprintf("%s = ? AND %s = '$val'", $this->autoincKeyName, $key), + $id + ); + } + return $this->db->quoteInto( sprintf('%s = ?', $this->autoincKeyName), $id