Include hidden fields for formulas

This commit is contained in:
Adria Navarro 2024-12-19 13:48:10 +01:00
parent 0ee432dd9a
commit 5a9ed4ff52
1 changed files with 18 additions and 5 deletions

View File

@ -55,12 +55,16 @@ const MISSING_COLUMN_REGEX = new RegExp(`no such column: .+`)
const MISSING_TABLE_REGX = new RegExp(`no such table: .+`) const MISSING_TABLE_REGX = new RegExp(`no such table: .+`)
const DUPLICATE_COLUMN_REGEX = new RegExp(`duplicate column name: .+`) const DUPLICATE_COLUMN_REGEX = new RegExp(`duplicate column name: .+`)
async function buildInternalFieldList( export async function buildInternalFieldList(
source: Table | ViewV2, source: Table | ViewV2,
tables: Table[], 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[] = [] let schemaFields: string[] = []
const isView = sdk.views.isView(source) const isView = sdk.views.isView(source)
@ -75,7 +79,7 @@ async function buildInternalFieldList(
schemaFields = Object.keys(helpers.views.basicFields(source)) schemaFields = Object.keys(helpers.views.basicFields(source))
} else { } else {
schemaFields = Object.keys(source.schema).filter( schemaFields = Object.keys(source.schema).filter(
key => source.schema[key].visible !== false key => includeHiddenFields || source.schema[key].visible !== false
) )
} }
@ -109,10 +113,16 @@ async function buildInternalFieldList(
} }
for (let key of schemaFields) { for (let key of schemaFields) {
const col = table.schema[key] const col = table.schema[key]
if ([FieldType.FORMULA, FieldType.AI].includes(col.type)) {
continue
}
const isRelationship = col.type === FieldType.LINK const isRelationship = col.type === FieldType.LINK
if (!relationships && isRelationship) { if (!relationships && isRelationship) {
continue continue
} }
if (!isRelationship) { if (!isRelationship) {
fieldList.push(`${table._id}.${mapToUserColumn(key)}`) fieldList.push(`${table._id}.${mapToUserColumn(key)}`)
} else { } else {
@ -121,6 +131,7 @@ async function buildInternalFieldList(
if (!relatedTable) { if (!relatedTable) {
continue continue
} }
// a quirk of how junction documents work in Budibase, refer to the "LinkDocument" type to see the full // 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" // 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 // we don't use an independent junction table ID for each separate relationship between two tables. For
@ -128,7 +139,9 @@ async function buildInternalFieldList(
// end up in the same junction table ID. We need to retrieve the field name property of the junction documents // 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. // as part of the relationship to tell us which relationship column the junction is related to.
const relatedFields = ( const relatedFields = (
await buildInternalFieldList(relatedTable, tables) await buildInternalFieldList(relatedTable, tables, {
includeHiddenFields: containsFormula,
})
).concat( ).concat(
getJunctionFields(relatedTable, ["doc1.fieldName", "doc2.fieldName"]) getJunctionFields(relatedTable, ["doc1.fieldName", "doc2.fieldName"])
) )