From 46c37ea0ca031729bfaec4c2afdc23284d0a3f87 Mon Sep 17 00:00:00 2001
From: Sebastian Listl <s.listl@adito.de>
Date: Mon, 5 Oct 2020 11:55:02 +0200
Subject: [PATCH] #1066606 ObjectRelation deletion

---
 .../recordcontainers/jdito/contentProcess.js    | 17 ++++++-----------
 .../recordcontainers/jdito/onDelete.js          |  3 +--
 process/DuplicateScanner_lib/process.js         |  3 ++-
 3 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js
index 4ea71164c3..c36c8c3e14 100644
--- a/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js
@@ -144,7 +144,7 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId,
         else // no ObjectType chosen
         {
             // load all ObjectRelationTypes
-            var relationTypes = _getPossibleRelationTypes(pObjectType);
+            var relationTypes = ObjectRelationUtils.getPossibleRelationTypes([pObjectType], true);
             
             relationTypes.forEach(function (relationType, i)
             {
@@ -238,8 +238,7 @@ function _getEntryData(pObjectId, pDirection, pRelationType1, pRelationType2, pP
     
     onConditionForRelationTypeJoin = newWhere("AB_OBJECTRELATIONTYPEID = AB_OBJECTRELATIONTYPE" + myNum)
         .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pRelationType1)
-        .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pRelationType2)
-        .andIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", pObjectRelationId || null); // set id to null, as only null works with .andIfSet
+        .and("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pRelationType2);
     
     // wird benoetigt zum Bearbeiten 
     if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
@@ -259,23 +258,19 @@ function _getEntryData(pObjectId, pDirection, pRelationType1, pRelationType2, pP
     var data = newSelect("OBJECT" + (pObjectRelationId ? myNum : otherNum) + "_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE, INFO, AB_OBJECTRELATIONTYPEID")
         .from("AB_OBJECTRELATION")
         .join("AB_OBJECTRELATIONTYPE", onConditionForRelationTypeJoin)
+        .whereIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", pObjectRelationId || null) // set id to null, as only null works with .andIfSet
         .table();
                         
     // try again with other side for "same"
-    if (data.length == 0 && pDirection == "same" && !pNoRecursion || pObjectRelationId && data.length > 0 && !data[0][0])
-         return _getEntryData(pObjectId, "normal", pRelationType1, pRelationType2, pPrevId, true, pObjectRelationId)
+    if (data.length == 0 && pDirection == "same" && !pNoRecursion || pObjectRelationId && data.length > 0 && !data[0][0]
+        || data.length == 0 && pDirection == "reverse" && !pNoRecursion && pObjectRelationId)
+         return _getEntryData(pObjectId, "normal", pRelationType1, pRelationType2, pPrevId, true, pObjectRelationId);
     
     // TODO: BINDATA?
     //for ( var i = 0; i < data.length; i++)  data[i][2] = image[data[i][2]] == undefined ? "" : image[data[i][2]];
     return data;
 }
 
-function _getPossibleRelationTypes(pObjectType)
-{
-    // TODO: load from entity when possible
-    return ObjectRelationUtils.getPossibleRelationTypes([pObjectType], true);
-}
-
 /**
  * insert a new Entry
  * 
diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/onDelete.js b/entity/ObjectTree_entity/recordcontainers/jdito/onDelete.js
index 415b1925a9..6541f935b8 100644
--- a/entity/ObjectTree_entity/recordcontainers/jdito/onDelete.js
+++ b/entity/ObjectTree_entity/recordcontainers/jdito/onDelete.js
@@ -3,5 +3,4 @@ import("Sql_lib");
 
 var objectRelationId = vars.get("$local.rowdata")["OBJECTRELATIONID.value"];
 
-newWhereIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId).deleteData();
-
+newWhereIfSet("AB_OBJECTRELATION.AB_OBJECTRELATIONID", objectRelationId).deleteData();
\ No newline at end of file
diff --git a/process/DuplicateScanner_lib/process.js b/process/DuplicateScanner_lib/process.js
index 983c5c2745..12420f6405 100644
--- a/process/DuplicateScanner_lib/process.js
+++ b/process/DuplicateScanner_lib/process.js
@@ -1104,7 +1104,8 @@ _DuplicateScannerUtils._migrateParticipantsToNewContact = function (pTableName,
 {
     var excludedIds = newSelect(pAssignableIdColumn)
         .from(pTableName)
-        .where([pTableName, pContactIdColumn], pTargetContactId);
+        .where([pTableName, pContactIdColumn], pTargetContactId)
+        .arrayColumn();
 
     var updateCount = newWhere([pTableName, pAssignableIdColumn], excludedIds, SqlBuilder.NOT_IN())
         .and([pTableName, pContactIdColumn], pSourceContactId)
-- 
GitLab