- Sepcial corner case when loading objects with external keys and these externla keys themsleves have reconciliation keys that are also externla keys.

Example: On a person the field location_id
Can be specified by Location->Name and Location->Owner Organization (The 2 reconciliation keys for the class Location). The latter is also an external key, and therefore only an Id can be supplied for this field. Note that Location->Owner Organization->Name is not yet supported.

SVN:trunk[738]
This commit is contained in:
Denis Flaven
2010-09-01 17:27:18 +00:00
parent 22aef82b83
commit b0d89dece3
2 changed files with 18 additions and 6 deletions

View File

@@ -274,6 +274,7 @@ class BulkChange
if ($oExtKey->IsNullAllowed())
{
$oTargetObj->Set($sAttCode, $oExtKey->GetNullValue());
$aResults[$sAttCode]= new CellStatus_Issue(null, $oTargetObj->Get($sAttCode), 'Object not found');
}
else
{

View File

@@ -58,9 +58,11 @@ function IsIdField($sClassName, $sFieldCode)
/**
* Get all the fields xxx->yyy based on the field xxx which is an external key
* @param string $sExtKeyAttCode Attribute code of the external key
* @param AttributeDefinition $oExtKeyAttDef Attribute definition of the external key
* @param bool $bAdvanced True if advanced mode
* @return Ash List of codes=>display name: xxx->yyy where yyy are the reconciliation keys for the object xxx
*/
function GetMappingsForExtKey($sAttCode, AttributeDefinition $oExtKeyAttDef)
function GetMappingsForExtKey($sAttCode, AttributeDefinition $oExtKeyAttDef, $bAdvanced)
{
$aResult = array();
$sTargetClass = $oExtKeyAttDef->GetTargetClass();
@@ -68,7 +70,11 @@ function GetMappingsForExtKey($sAttCode, AttributeDefinition $oExtKeyAttDef)
{
if (MetaModel::IsReconcKey($sTargetClass, $sTargetAttCode))
{
$aResult[$sAttCode.'->'.$sTargetAttCode] = $oExtKeyAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel();
if ($bAdvanced || !$oTargetAttDef->IsExternalKey())
{
// When not in advanced mode do not allow to use reconciliation keys (on external keys) if they are themselves external keys !
$aResult[$sAttCode.'->'.$sTargetAttCode] = $oExtKeyAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel();
}
}
}
return $aResult;
@@ -118,10 +124,15 @@ function GetMappingForField($sClassName, $sFieldName, $iFieldIndex, $bAdvancedMo
{
if (MetaModel::IsReconcKey($sTargetClass, $sTargetAttCode))
{
$aChoices[$sAttCode.'->'.$sTargetAttCode] = $oAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel();
if ((strcasecmp($sFieldName, $aChoices[$sAttCode.'->'.$sTargetAttCode]) == 0) || (strcasecmp($sFieldName, ($sAttCode.'->'.$sTargetAttCode)) == 0) )
if ($bAdvancedMode || (!$oTargetAttDef->IsExternalKey()))
{
$sFieldCode = $sAttCode.'->'.$sTargetAttCode;
// When not in advanced mode do not allow to use reconciliation keys (on external keys) if they are themselves external keys !
$aChoices[$sAttCode.'->'.$sTargetAttCode] = $oAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel();
if ((strcasecmp($sFieldName, $aChoices[$sAttCode.'->'.$sTargetAttCode]) == 0) || (strcasecmp($sFieldName, ($sAttCode.'->'.$sTargetAttCode)) == 0) )
{
$sFieldCode = $sAttCode.'->'.$sTargetAttCode;
}
}
}
}
@@ -303,7 +314,7 @@ switch($sOperation)
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
if ($oAttDef->IsExternalKey())
{
$aMoreReconciliationKeys = array_keys(GetMappingsForExtKey($sAttCode, $oAttDef));
$aMoreReconciliationKeys = array_keys(GetMappingsForExtKey($sAttCode, $oAttDef, $bAdvanced));
}
}
$sDefaultKeys = '"'.implode('", "',array_merge($aReconciliationKeys,$aMoreReconciliationKeys)).'"';