This commit is contained in:
Adria Navarro 2024-09-24 17:56:07 +02:00
parent 53b4634cff
commit 7a7ce3dc62
1 changed files with 7 additions and 4 deletions

View File

@ -10,7 +10,7 @@ import flatten from "lodash/flatten"
import { USER_METDATA_PREFIX } from "../utils" import { USER_METDATA_PREFIX } from "../utils"
import partition from "lodash/partition" import partition from "lodash/partition"
import { getGlobalUsersFromMetadata } from "../../utilities/global" import { getGlobalUsersFromMetadata } from "../../utilities/global"
import { processFormulas } from "../../utilities/rowProcessor" import { outputProcessing, processFormulas } from "../../utilities/rowProcessor"
import { context, features } from "@budibase/backend-core" import { context, features } from "@budibase/backend-core"
import { import {
ContextUser, ContextUser,
@ -275,7 +275,7 @@ export async function squashLinks<T = Row[] | Row>(
// will populate this as we find them // will populate this as we find them
const linkedTables = [table] const linkedTables = [table]
const isArray = Array.isArray(enriched) const isArray = Array.isArray(enriched)
const enrichedArray = !isArray ? [enriched] : enriched const enrichedArray = !isArray ? [enriched as Row] : (enriched as Row[])
for (const row of enrichedArray) { for (const row of enrichedArray) {
// this only fetches the table if its not already in array // this only fetches the table if its not already in array
const rowTable = await getLinkedTable(row.tableId!, linkedTables) const rowTable = await getLinkedTable(row.tableId!, linkedTables)
@ -292,6 +292,9 @@ export async function squashLinks<T = Row[] | Row>(
obj.primaryDisplay = getPrimaryDisplayValue(link, linkedTable) obj.primaryDisplay = getPrimaryDisplayValue(link, linkedTable)
if (viewSchema[column]?.columns) { if (viewSchema[column]?.columns) {
const enrichedLink = await outputProcessing(linkedTable, link, {
squash: false,
})
const squashFields = Object.entries(viewSchema[column].columns) const squashFields = Object.entries(viewSchema[column].columns)
.filter(([columnName, viewColumnConfig]) => { .filter(([columnName, viewColumnConfig]) => {
const tableColumn = linkedTable.schema[columnName] const tableColumn = linkedTable.schema[columnName]
@ -312,7 +315,7 @@ export async function squashLinks<T = Row[] | Row>(
.map(([columnName]) => columnName) .map(([columnName]) => columnName)
for (const relField of squashFields) { for (const relField of squashFields) {
obj[relField] = link[relField] obj[relField] = enrichedLink[relField]
} }
} }
@ -321,5 +324,5 @@ export async function squashLinks<T = Row[] | Row>(
row[column] = newLinks row[column] = newLinks
} }
} }
return isArray ? enrichedArray : enrichedArray[0] return (isArray ? enrichedArray : enrichedArray[0]) as T
} }