From aa9c7c70916967926bf00a0e644b7a25da5666e2 Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Tue, 25 Sep 2012 08:29:06 +0000 Subject: [PATCH] Protects against temporary objects that exist only in memory (id < 0) SVN:trunk[2202] --- core/dbobject.class.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 1468b3394..dc217bccc 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -451,7 +451,7 @@ abstract class DBObject // $sExtKeyAttCode = $oAttDef->GetKeyAttCode(); - if ($iRemote = $this->Get($sExtKeyAttCode)) + if (($iRemote = $this->Get($sExtKeyAttCode)) && ($iRemote > 0)) // Objects in memory have negative IDs { $oExtKeyAttDef = MetaModel::GetAttributeDef(get_class($this), $sExtKeyAttCode); $oRemote = MetaModel::GetObject($oExtKeyAttDef->GetTargetClass(), $iRemote); @@ -558,8 +558,16 @@ abstract class DBObject //return $this->Get($sAttCode.'_friendlyname'); $sTargetClass = $oAtt->GetTargetClass(EXTKEY_ABSOLUTE); $iTargetKey = $this->Get($sAttCode); - $sLabel = $this->Get($sAttCode.'_friendlyname'); - return $this->MakeHyperLink($sTargetClass, $iTargetKey, $sLabel); + if ($iTargetKey < 0) + { + // the key points to an object that exists only in memory... no hyperlink points to it yet + return ''; + } + else + { + $sLabel = $this->Get($sAttCode.'_friendlyname'); + return $this->MakeHyperLink($sTargetClass, $iTargetKey, $sLabel); + } } // That's a standard attribute (might be an ext field or a direct field, etc.)