|
|
@ -203,19 +203,17 @@ exports.attachFullLinkedDocs = async (ctx, table, rows) => { |
|
|
exports.squashLinksToPrimaryDisplay = async (appId, table, enriched) => { |
|
|
exports.squashLinksToPrimaryDisplay = async (appId, table, enriched) => { |
|
|
const db = new CouchDB(appId) |
|
|
const db = new CouchDB(appId) |
|
|
// will populate this as we find them
|
|
|
// will populate this as we find them
|
|
|
const linkedTables = [] |
|
|
const linkedTables = [table] |
|
|
for (let [column, schema] of Object.entries(table.schema)) { |
|
|
for (let row of enriched) { |
|
|
if (schema.type !== FieldTypes.LINK) { |
|
|
// this only fetches the table if its not already in array
|
|
|
continue |
|
|
const rowTable = await getLinkedTable(db, row.tableId, linkedTables) |
|
|
} |
|
|
for (let [column, schema] of Object.entries(rowTable.schema)) { |
|
|
for (let row of enriched) { |
|
|
if (schema.type !== FieldTypes.LINK || !Array.isArray(row[column])) { |
|
|
if (!row[column] || !row[column].length) { |
|
|
|
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
|
const newLinks = [] |
|
|
const newLinks = [] |
|
|
for (let link of row[column]) { |
|
|
for (let link of row[column]) { |
|
|
const linkTblId = link.tableId || getRelatedTableForField(table, column) |
|
|
const linkTblId = link.tableId || getRelatedTableForField(table, column) |
|
|
// this only fetches the table if its not already in array
|
|
|
|
|
|
const linkedTable = await getLinkedTable(db, linkTblId, linkedTables) |
|
|
const linkedTable = await getLinkedTable(db, linkTblId, linkedTables) |
|
|
const obj = { _id: link._id } |
|
|
const obj = { _id: link._id } |
|
|
if (link[linkedTable.primaryDisplay]) { |
|
|
if (link[linkedTable.primaryDisplay]) { |
|
|
|