Only walk path on toOne and toMany
authorBen Thompson <ben@xtuple.com>
Thu, 5 Jun 2014 23:23:33 +0000 (19:23 -0400)
committerBen Thompson <ben@xtuple.com>
Thu, 5 Jun 2014 23:23:33 +0000 (19:23 -0400)
lib/orm/source/xt/javascript/data.sql

index a975c07..0cacd18 100644 (file)
@@ -114,28 +114,30 @@ select xt.install_js('XT','Data','xtuple', $$
                 subChildOrm,
                 naturalKey;
 
-              if (currentProp.toOne && currentProp.toOne.type) {
-                subChildOrm = that.fetchOrm(nameSpace, currentProp.toOne.type);
-              } else if (currentProp.toMany && currentProp.toMany.type) {
-                subChildOrm = that.fetchOrm(nameSpace, currentProp.toMany.type);
-              } else {
-                plv8.elog(ERROR, "toOne or toMany property is missing it's 'type': " + currentProp.name);
-              }
+              if ((currentProp.toOne || currentProp.toMany)) {
+                if (currentProp.toOne && currentProp.toOne.type) {
+                  subChildOrm = that.fetchOrm(nameSpace, currentProp.toOne.type);
+                } else if (currentProp.toMany && currentProp.toMany.type) {
+                  subChildOrm = that.fetchOrm(nameSpace, currentProp.toMany.type);
+                } else {
+                  plv8.elog(ERROR, "toOne or toMany property is missing it's 'type': " + currentProp.name);
+                }
 
-              if (pathIndex < pathParts.length - 1) {
-                /* Recurse. */
-                walkPath(pathParts, subChildOrm, pathIndex + 1);
-              } else {
-                /* This is the end of the path. */
-                naturalKey = XT.Orm.naturalKey(subChildOrm);
-                if (currentAttributeIsString) {
-                  /* add the natural key to the end of the requested attribute */
-                  parameter.attribute = attribute + "." + naturalKey;
+                if (pathIndex < pathParts.length - 1) {
+                  /* Recurse. */
+                  walkPath(pathParts, subChildOrm, pathIndex + 1);
                 } else {
-                  /* swap out the attribute in the array for the one with the prepended natural key */
-                  index = parameter.attribute.indexOf(attribute);
-                  parameter.attribute.splice(index, 1);
-                  parameter.attribute.splice(index, 0, attribute + "."  + naturalKey);
+                  /* This is the end of the path. */
+                  naturalKey = XT.Orm.naturalKey(subChildOrm);
+                  if (currentAttributeIsString) {
+                    /* add the natural key to the end of the requested attribute */
+                    parameter.attribute = attribute + "." + naturalKey;
+                  } else {
+                    /* swap out the attribute in the array for the one with the prepended natural key */
+                    index = parameter.attribute.indexOf(attribute);
+                    parameter.attribute.splice(index, 1);
+                    parameter.attribute.splice(index, 0, attribute + "."  + naturalKey);
+                  }
                 }
               }
             }