From 1ef946aedb72baf23817b379bd5a6ed615be5250 Mon Sep 17 00:00:00 2001 From: zYne Date: Fri, 3 Aug 2007 21:02:17 +0000 Subject: [PATCH] --- lib/Doctrine/Record.php | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index b2148dd69..da28de8d8 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -451,6 +451,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count switch ($this->_table->getIdentifierType()) { case Doctrine::IDENTIFIER_AUTOINC: case Doctrine::IDENTIFIER_SEQUENCE: + case Doctrine::IDENTIFIER_NATURAL: $name = $this->_table->getIdentifier(); if ($exists) { @@ -458,20 +459,9 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count $this->_id[$name] = $this->_data[$name]; } } - - unset($this->_data[$name]); - - break; - case Doctrine::IDENTIFIER_NATURAL: - $this->_id = array(); - $name = $this->_table->getIdentifier(); - - if (isset($this->_data[$name]) && $this->_data[$name] !== self::$_null) { - $this->_id[$name] = $this->_data[$name]; - } break; case Doctrine::IDENTIFIER_COMPOSITE: - $names = $this->_table->getIdentifier(); + $names = $this->_table->getIdentifier(); foreach ($names as $name) { if ($this->_data[$name] === self::$_null) { @@ -1170,13 +1160,24 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count */ public function copy() { - $ret = $this->_table->create($this->_data); + $data = $this->_data; + + if ($this->_table->getIdentifierType() === Doctrine::IDENTIFIER_AUTOINC) { + $id = $this->_table->getIdentifier(); + + unset($data[$id]); + } + + $ret = $this->_table->create($data); $modified = array(); - foreach ($this->_data as $key => $val) { + + foreach ($data as $key => $val) { if ( ! ($val instanceof Doctrine_Null)) { $ret->_modified[] = $key; } } + + return $ret; } /** @@ -1218,9 +1219,9 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count $this->_state = Doctrine_Record::STATE_CLEAN; $this->_modified = array(); } else { - $name = $this->_table->getIdentifier(); - + $name = $this->_table->getIdentifier(); $this->_id[$name] = $id; + $this->_data[$name] = $id; $this->_state = Doctrine_Record::STATE_CLEAN; $this->_modified = array(); }