diff --git a/core/dbobject.class.php b/core/dbobject.class.php index cb444e50b0..59049c7c24 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -2792,12 +2792,6 @@ abstract class DBObject implements iDisplay $this->DoComputeValues(); $this->OnInsert(); - if ($this->m_iKey < 0) - { - // This was a temporary "memory" key: discard it so that DBInsertSingleTable will not try to use it! - $this->m_iKey = null; - } - // If not automatically computed, then check that the key is given by the caller if (!MetaModel::IsAutoIncrementKey($sRootClass)) { @@ -2814,6 +2808,12 @@ abstract class DBObject implements iDisplay throw new CoreCannotSaveObjectException(array('issues' => $aIssues, 'class' => get_class($this), 'id' => $this->GetKey())); } + if ($this->m_iKey < 0) + { + // This was a temporary "memory" key: discard it so that DBInsertSingleTable will not try to use it! + $this->m_iKey = null; + } + // Stop watches $sState = $this->GetState(); if ($sState != '')