Fixing formula in enrichment calls, it did not retrieve the correct linked table for output processing, grouping rows for enrichment phase with their correct tables.

This commit is contained in:
mike12345567 2021-09-30 17:54:54 +01:00
parent 4ecc92de3b
commit 5bafd1c01b
2 changed files with 43 additions and 779 deletions

View File

@ -403,16 +403,32 @@ exports.fetchEnrichedRow = async ctx => {
rowId,
})
// look up the actual rows based on the ids
const response = await db.allDocs({
include_docs: true,
keys: linkVals.map(linkVal => linkVal.id),
})
// need to include the IDs in these rows for any links they may have
let linkedRows = await outputProcessing(
ctx,
table,
response.rows.map(row => row.doc)
)
let response = (
await db.allDocs({
include_docs: true,
keys: linkVals.map(linkVal => linkVal.id),
})
).rows.map(row => row.doc)
// group responses by table
let groups = {},
tables = {}
for (let row of response) {
const linkedTableId = row.tableId
if (groups[linkedTableId] == null) {
groups[linkedTableId] = [row]
tables[linkedTableId] = await db.get(linkedTableId)
} else {
groups[linkedTableId].push(row)
}
}
let linkedRows = []
for (let [tableId, rows] of Object.entries(groups)) {
// need to include the IDs in these rows for any links they may have
linkedRows = linkedRows.concat(
await outputProcessing(ctx, tables[tableId], rows)
)
}
// insert the link rows in the correct place throughout the main row
for (let fieldName of Object.keys(table.schema)) {
let field = table.schema[fieldName]

File diff suppressed because it is too large Load Diff