@ -403,16 +403,32 @@ exports.fetchEnrichedRow = async ctx => {
rowId ,
rowId ,
} )
} )
// look up the actual rows based on the ids
// look up the actual rows based on the ids
const response = await db . allDocs ( {
let response = (
include_docs : true ,
await db . allDocs ( {
keys : linkVals . map ( linkVal => linkVal . id ) ,
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 (
) . rows . map ( row => row . doc )
ctx ,
// group responses by table
table ,
let groups = { } ,
response . rows . map ( row => row . doc )
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
// insert the link rows in the correct place throughout the main row
for ( let fieldName of Object . keys ( table . schema ) ) {
for ( let fieldName of Object . keys ( table . schema ) ) {
let field = table . schema [ fieldName ]
let field = table . schema [ fieldName ]