From 6aa55c3c80961e72441b96d482757656e1dc73ad Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Tue, 8 Oct 2019 11:18:09 +0200
Subject: [PATCH] fix join

---
 process/Sql_lib/process.js | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/process/Sql_lib/process.js b/process/Sql_lib/process.js
index 54d0a299dfd..61d69095322 100644
--- a/process/Sql_lib/process.js
+++ b/process/Sql_lib/process.js
@@ -904,9 +904,13 @@ SqlBuilder.prototype.join = function(pTable, pCondition, pAlias, pPrefix)
     if (pAlias)
         postfix = pAlias + " " + postfix;
     
-    var joinPart = SqlBuilder._getStatement(pTable, "join", postfix);
+    var joinPart = SqlBuilder._getStatement(pTable, prefix, postfix);
     var conditionPart = SqlBuilder._getStatement(pCondition);
-    this._joins.push(SqlBuilder.mergePreparedQueries([joinPart, conditionPart]));
+    
+    joinPart._sqlStorage += " " + conditionPart._sqlStorage;
+    joinPart.preparedValues = joinPart.preparedValues.concat(conditionPart.preparedValues);
+    
+    this._joins.push(joinPart)
     return this;
 }
 
@@ -1553,14 +1557,16 @@ SqlBuilder._getStatement = function (pElement, pPrefix, pPostfix, pAutoJoin)
         preparedValues: preparedValues,
         _sqlStorage: pElement.toString()
     };
-    
+
     function _getElement (element)
     {
         var isSubQuery = false;
         if (element instanceof SqlBuilder)
         {
+            if (element.isFullSelect())
+                isSubQuery = true;
+                
             element = element.build();
-            isSubQuery = true;
         }
         preparedValues = preparedValues.concat(element[1]);
         if (isSubQuery || pAutoJoin)
-- 
GitLab