Skip to content

Commit

Permalink
Include hidden fields for formulas
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr committed Dec 19, 2024
1 parent 0ee432d commit 5a9ed4f
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions packages/server/src/sdk/app/rows/search/internal/sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ const MISSING_COLUMN_REGEX = new RegExp(`no such column: .+`)
const MISSING_TABLE_REGX = new RegExp(`no such table: .+`)
const DUPLICATE_COLUMN_REGEX = new RegExp(`duplicate column name: .+`)

async function buildInternalFieldList(
export async function buildInternalFieldList(
source: Table | ViewV2,
tables: Table[],
opts?: { relationships?: RelationshipsJson[]; allowedFields?: string[] }
opts?: {
relationships?: RelationshipsJson[]
allowedFields?: string[]
includeHiddenFields?: boolean
}
) {
const { relationships, allowedFields } = opts || {}
const { relationships, allowedFields, includeHiddenFields } = opts || {}
let schemaFields: string[] = []

const isView = sdk.views.isView(source)
Expand All @@ -75,7 +79,7 @@ async function buildInternalFieldList(
schemaFields = Object.keys(helpers.views.basicFields(source))
} else {
schemaFields = Object.keys(source.schema).filter(
key => source.schema[key].visible !== false
key => includeHiddenFields || source.schema[key].visible !== false
)
}

Expand Down Expand Up @@ -109,10 +113,16 @@ async function buildInternalFieldList(
}
for (let key of schemaFields) {
const col = table.schema[key]

if ([FieldType.FORMULA, FieldType.AI].includes(col.type)) {
continue
}

const isRelationship = col.type === FieldType.LINK
if (!relationships && isRelationship) {
continue
}

if (!isRelationship) {
fieldList.push(`${table._id}.${mapToUserColumn(key)}`)
} else {
Expand All @@ -121,14 +131,17 @@ async function buildInternalFieldList(
if (!relatedTable) {
continue
}

// a quirk of how junction documents work in Budibase, refer to the "LinkDocument" type to see the full
// structure - essentially all relationships between two tables will be inserted into a single "table"
// we don't use an independent junction table ID for each separate relationship between two tables. For
// example if we have table A and B, with two relationships between them, all the junction documents will
// end up in the same junction table ID. We need to retrieve the field name property of the junction documents
// as part of the relationship to tell us which relationship column the junction is related to.
const relatedFields = (
await buildInternalFieldList(relatedTable, tables)
await buildInternalFieldList(relatedTable, tables, {
includeHiddenFields: containsFormula,
})
).concat(
getJunctionFields(relatedTable, ["doc1.fieldName", "doc2.fieldName"])
)
Expand Down

0 comments on commit 5a9ed4f

Please sign in to comment.