From fa38ee88de0dd26f0be4e20c329d8057affceacd Mon Sep 17 00:00:00 2001 From: nbm Date: Tue, 18 Apr 2006 14:47:30 +0000 Subject: [PATCH] Add a helper method to KTEntity-based objects. newCopy will make a new copy of the object with a new id. This is the preferred way to create a "copy" of an object. --- lib/ktentity.inc | 13 +++++++++++++ 1 file changed, 13 insertions(+), 0 deletions(-) diff --git a/lib/ktentity.inc b/lib/ktentity.inc index c59cfa4..a82c0e9 100644 --- a/lib/ktentity.inc +++ b/lib/ktentity.inc @@ -111,6 +111,19 @@ class KTEntity { return false; } + function newCopy() { + $sClass = get_class($this); + $oObject =& new $sClass; + foreach (array_keys($this->_aFieldToSelect) as $k) { + $oObject->$k = $this->$k; + } + $oObject->iId = -1; + $oObject->create(); + + $iId = $oObject->iId; + return KTEntityUtil::get($sClass, $iId); + } + /** * Update the values in the database table with the object's current values * -- libgit2 0.21.4