issue #23323: combine orm extensions with paths
authorSteve Hackbarth <stephenhackbarth@gmail.com>
Sat, 19 Apr 2014 03:22:53 +0000 (23:22 -0400)
committerSteve Hackbarth <stephenhackbarth@gmail.com>
Sat, 19 Apr 2014 03:22:53 +0000 (23:22 -0400)
lib/orm/source/xt/javascript/data.sql
test/database/joins.js

index 8395978..23280cb 100644 (file)
@@ -348,6 +348,20 @@ select xt.install_js('XT','Data','xtuple', $$
                       childOrm = this.fetchOrm(nameSpace, prop.toOne.type);
                     }
                   } else {
+                    pertinentExtension = XT.Orm.getProperty(childOrm, parts[n], true);
+                    var isExtension = pertinentExtension.isChild || pertinentExtension.isExtension;
+                    if(isExtension) {
+                      /* We'll need to join this orm extension */
+                      fromKeyProp = XT.Orm.getProperty(orm, pertinentExtension.relations[0].inverse);
+                      joinIdentifiers.push(
+                        this.getNamespaceFromNamespacedTable(pertinentExtension.table),
+                        this.getTableFromNamespacedTable(pertinentExtension.table),
+                        fromKeyProp.attr.column,
+                        pertinentExtension.relations[0].column);
+                      joins.push("left join %" + (joinIdentifiers.length - 3) + "$I.%" + (joinIdentifiers.length - 2)
+                        + "$I jt" + joins.length + " on t1.%"
+                        + (joinIdentifiers.length - 1) + "$I = jt" + joins.length + ".%" + joinIdentifiers.length + "$I");
+                    }
                     /* Build path, e.g. table_name.column_name */
                     if (n === parts.length - 1) {
                       identifiers.push("jt" + (joins.length - 1));
@@ -357,7 +371,7 @@ select xt.install_js('XT','Data','xtuple', $$
                         params[pcount] = "lower(" + params[pcount] + ")";
                       }
                     } else {
-                      sourceTableAlias = n === 0 ? "t1" : "jt" + (joins.length - 1);
+                      sourceTableAlias = n === 0 && !isExtension ? "t1" : "jt" + (joins.length - 1);
                       if (prop.toOne && prop.toOne.type) {
                         childOrm = this.fetchOrm(nameSpace, prop.toOne.type);
                         joinIdentifiers.push(
index 484c4da..6b5834c 100644 (file)
@@ -310,10 +310,13 @@ var _ = require("underscore"),
       });
     });
 
+// incident plus
+//select xt.js_init(true);select xt.get($${"nameSpace":"XM","type":"IncidentListItem","query":{"orderBy":[{"attribute":"priorityOrder"},{"attribute":"updated","descending":true},{"attribute":"number","descending":true,"numeric":true}],"rowOffset":0,"rowLimit":50,"parameters":[{"attribute":["owner.username","assignedTo.username"],"operator":"","isCharacteristic":false,"value":"admin"},{"attribute":"project","operator":"","isCharacteristic":false,"value":"GREENLEAF"},{"attribute":"foundIn","operator":"","isCharacteristic":false,"value":"d0e6c507-eac5-461c-f63e-91e352a3ffb1"}]},"username":"admin","encryptionKey":"this is any content"}$$)
 
 
 
-    // T&E
+// T&E
+//select xt.js_init(true);select xt.get($${"nameSpace":"XM","type":"ProjectListItem","query":{"orderBy":[{"attribute":"number"}],"rowOffset":0,"rowLimit":50,"parameters":[{"attribute":["number","name","projectType","status","department"],"operator":"MATCHES","value":"foo"},{"attribute":"status","operator":"!=","value":"C"},{"attribute":"number","operator":"MATCHES","isCharacteristic":false,"value":"tre"},{"attribute":["owner.username","assignedTo.username"],"operator":"","isCharacteristic":false,"value":"admin"}]},"username":"admin","encryptionKey":"this is any content"}$$)
 //select xt.js_init(true);select xt.get($${"nameSpace":"XM","type":"ItemRelation","query":{"parameters":[{"attribute":"projectExpenseMethod","operator":"=","value":"E"},{"attribute":"isActive","value":true},{"attribute":"number","operator":"BEGINS_WITH","value":"pro","keySearch":false}],"orderBy":[{"attribute":"number"}],"rowLimit":1},"username":"admin","encryptionKey":"this is any content"}$$)
 //select xt.js_init(true);select xt.get($${"nameSpace":"XM","type":"ItemRelation","query":{"parameters":[{"attribute":"projectExpenseMethod","operator":"ANY","value":["E","A"]},{"attribute":"isActive","value":true},{"attribute":"number","operator":"BEGINS_WITH","value":"pro","keySearch":false}],"orderBy":[{"attribute":"number"}],"rowLimit":1},"username":"admin","encryptionKey":"this is any content"}$$)