Merge pull request #5542 from Budibase/fix/5495
Fix for SQL relationship based formulas
This commit is contained in:
commit
ae385ffd16
|
@ -60,6 +60,7 @@ export function getBindings({
|
||||||
)
|
)
|
||||||
|
|
||||||
const label = path == null ? column : `${path}.0.${column}`
|
const label = path == null ? column : `${path}.0.${column}`
|
||||||
|
const binding = path == null ? `[${column}]` : `${path}.0.[${column}]`
|
||||||
// only supply a description for relationship paths
|
// only supply a description for relationship paths
|
||||||
const description =
|
const description =
|
||||||
path == null
|
path == null
|
||||||
|
@ -73,8 +74,8 @@ export function getBindings({
|
||||||
description,
|
description,
|
||||||
// don't include path, it messes things up, relationship path
|
// don't include path, it messes things up, relationship path
|
||||||
// will be replaced by the main array binding
|
// will be replaced by the main array binding
|
||||||
readableBinding: column,
|
readableBinding: label,
|
||||||
runtimeBinding: `[${column}]`,
|
runtimeBinding: binding,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return bindings
|
return bindings
|
||||||
|
|
|
@ -323,6 +323,28 @@ module External {
|
||||||
return { row: newRow, manyRelationships }
|
return { row: newRow, manyRelationships }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
squashRelationshipColumns(
|
||||||
|
table: Table,
|
||||||
|
row: Row,
|
||||||
|
relationships: RelationshipsJson[]
|
||||||
|
): Row {
|
||||||
|
for (let relationship of relationships) {
|
||||||
|
const linkedTable = this.tables[relationship.tableName]
|
||||||
|
if (!linkedTable) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const display = linkedTable.primaryDisplay
|
||||||
|
for (let key of Object.keys(row[relationship.column])) {
|
||||||
|
const related: Row = row[relationship.column][key]
|
||||||
|
row[relationship.column][key] = {
|
||||||
|
primaryDisplay: display ? related[display] : undefined,
|
||||||
|
_id: related._id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return row
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This iterates through the returned rows and works out what elements of the rows
|
* This iterates through the returned rows and works out what elements of the rows
|
||||||
* actually match up to another row (based on primary keys) - this is pretty specific
|
* actually match up to another row (based on primary keys) - this is pretty specific
|
||||||
|
@ -354,12 +376,6 @@ module External {
|
||||||
if (!linked._id) {
|
if (!linked._id) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// if not returning full docs then get the minimal links out
|
|
||||||
const display = linkedTable.primaryDisplay
|
|
||||||
linked = {
|
|
||||||
primaryDisplay: display ? linked[display] : undefined,
|
|
||||||
_id: linked._id,
|
|
||||||
}
|
|
||||||
columns[relationship.column] = linked
|
columns[relationship.column] = linked
|
||||||
}
|
}
|
||||||
for (let [column, related] of Object.entries(columns)) {
|
for (let [column, related] of Object.entries(columns)) {
|
||||||
|
@ -417,7 +433,9 @@ module External {
|
||||||
relationships
|
relationships
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return processFormulas(table, Object.values(finalRows))
|
return processFormulas(table, Object.values(finalRows)).map((row: Row) =>
|
||||||
|
this.squashRelationshipColumns(table, row, relationships)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -27,7 +27,8 @@ module MySQLModule {
|
||||||
user: string
|
user: string
|
||||||
password: string
|
password: string
|
||||||
database: string
|
database: string
|
||||||
ssl?: object
|
ssl?: { [key: string]: any }
|
||||||
|
rejectUnauthorized: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const SCHEMA: Integration = {
|
const SCHEMA: Integration = {
|
||||||
|
@ -65,6 +66,11 @@ module MySQLModule {
|
||||||
type: DatasourceFieldTypes.OBJECT,
|
type: DatasourceFieldTypes.OBJECT,
|
||||||
required: false,
|
required: false,
|
||||||
},
|
},
|
||||||
|
rejectUnauthorized: {
|
||||||
|
type: DatasourceFieldTypes.BOOLEAN,
|
||||||
|
default: true,
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
query: {
|
query: {
|
||||||
create: {
|
create: {
|
||||||
|
@ -114,6 +120,16 @@ module MySQLModule {
|
||||||
if (config.ssl && Object.keys(config.ssl).length === 0) {
|
if (config.ssl && Object.keys(config.ssl).length === 0) {
|
||||||
delete config.ssl
|
delete config.ssl
|
||||||
}
|
}
|
||||||
|
// make sure this defaults to true
|
||||||
|
if (
|
||||||
|
config.rejectUnauthorized != null &&
|
||||||
|
!config.rejectUnauthorized &&
|
||||||
|
config.ssl
|
||||||
|
) {
|
||||||
|
config.ssl.rejectUnauthorized = config.rejectUnauthorized
|
||||||
|
}
|
||||||
|
// @ts-ignore
|
||||||
|
delete config.rejectUnauthorized
|
||||||
this.config = config
|
this.config = config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue