Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: bendiy/xtuple
...
head fork: bendiy/xtuple
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
View
38 lib/orm/source/xt/javascript/discovery.sql
@@ -114,14 +114,13 @@ select xt.install_js('XT','Discovery','xtuple', $$
}
}
- /* Schema section.
- discovery.schemas = XT.Discovery.getORMSchemas();
+ /* Schema section. */
+ discovery.schemas = XT.Discovery.getORMSchemas(orms);
if (!discovery.schemas) {
return false;
}
- */
/* Resources section. */
@@ -166,7 +165,7 @@ select xt.install_js('XT','Discovery','xtuple', $$
XT.Discovery.getIsRestORMs = function() {
/* TODO - Do we need to include "XM" in the propName? */
- var sql = "select orm_type from xt.orm where orm_rest group by orm_namespace, orm_type order by orm_namespace, orm_type",
+ var sql = "select orm_namespace, orm_type from xt.orm where orm_rest group by orm_namespace, orm_type order by orm_namespace, orm_type",
orms = plv8.execute(sql);
if (!orms.length) {
@@ -179,10 +178,8 @@ select xt.install_js('XT','Discovery','xtuple', $$
/*
* Helper function to get a JSON-Schema for all ORM Models.
*/
- XT.Discovery.getORMSchemas = function() {
- var sql = "select orm_namespace, orm_type from xt.orm group by orm_namespace, orm_type order by orm_namespace, orm_type",
- orms = plv8.execute(sql),
- schema = {};
+ XT.Discovery.getORMSchemas = function(orms) {
+ var schema = {};
if (!orms.length) {
return false;
@@ -192,7 +189,32 @@ select xt.install_js('XT','Discovery','xtuple', $$
for (var i = 0; i < orms.length; i++) {
/* TODO - Do we need to include "XM" in the propName? */
var propName = orms[i].orm_type;
+
+ /* Get parent ORM */
schema[propName] = XT.Schema.getProperties({"nameSpace": orms[i].orm_namespace, "type": orms[i].orm_type});
+
+ if (!schema[propName] || !schema[propName].properties) {
+ return false;
+ }
+
+ /* Drill down through schema and get all $ref schemas. */
+ for (var prop in schema[propName].properties) {
+ var childProp = schema[propName].properties[prop];
+
+ if (childProp) {
+ if (childProp.items && childProp.items["$ref"]){
+ var childOrm = childProp.items["$ref"];
+ } else if (childProp["$ref"]){
+ var childOrm = childProp["$ref"];
+ }
+
+ /* Only get this child schema if we don't already have it. */
+ if (childOrm && !schema[childOrm]) {
+ /* Recusing into children. */
+ schema = XT.extend(schema, XT.Discovery.getORMSchemas([{ "orm_namespace": "XM", "orm_type": childOrm }]));
+ }
+ }
+ }
}
return schema;
View
35 lib/orm/source/xt/javascript/schema.sql
@@ -23,9 +23,12 @@ select xt.install_js('XT','Schema','xtuple', $$
XT.Schema.columnInfo = function(ormSchemaTable, ormColumn) {
var schema,
table,
+ func,
schemaTable,
sql,
+ funcSql,
res,
+ funcRes,
ret = {};
/* Get the schema and table from the ORM table property. */
@@ -38,6 +41,30 @@ select xt.install_js('XT','Schema','xtuple', $$
table = schemaTable[1];
}
+ /* Check if this is a function and not a table. */
+ if (table.indexOf("(") !== -1) {
+ /* Extract just the function name from table. */
+ func = table.substring(0,table.indexOf("("));
+
+ /* Look up the "RETURNS SETOF" type. */
+ funcSql = 'select ' +
+ 'type_udt_schema, ' +
+ 'type_udt_name ' +
+ 'from information_schema.routines ' +
+ 'where 1=1 ' +
+ 'and specific_schema = $1 ' +
+ 'and routine_name = $2; ';
+
+ funcRes = plv8.execute(funcSql, [schema, func]);
+
+ if (funcRes.length === 1) {
+ /* Name of the schema that the return data type of the function is defined in */
+ schema = funcRes[0].type_udt_schema;
+ /* Name of the return data type of the function. */
+ table = funcRes[0].type_udt_name;
+ }
+ }
+
/* Query to get column's PostgreSQL datatype and other schema info. */
sql = 'select ' +
'data_type, ' +
@@ -246,7 +273,9 @@ select xt.install_js('XT','Schema','xtuple', $$
/* Get column's PostgreSQL datatype info. */
schemaColumnInfo = XT.Schema.columnInfo(schemaTable, column);
- if (!schemaColumnInfo) return false;
+ if (!schemaColumnInfo) {
+ return false;
+ }
/* Loop through the returned schemaColumnInfo properties and add them. */
for (var attrname in schemaColumnInfo) {
@@ -296,7 +325,9 @@ select xt.install_js('XT','Schema','xtuple', $$
}
/* If this ORM has no column properties, we have an empty object, return false. */
- if (!ret.properties || !Object.keys(ret.properties).length > 0) return false;
+ if (!ret.properties || !Object.keys(ret.properties).length > 0) {
+ return false;
+ }
/* return the results */
return ret;

No commit comments for this range

Something went wrong with that request. Please try again.